如何在datagridview中为男性和女性生成0和1的性别。我尝试使用下面的代码,它显示性对还是错
SqlConnection connection = new SqlConnection(connectionstring);
connection.Open();
SqlCommand command = new SqlCommand("select Institution as'Institution(4)', Branch as 'Branch(3)', CustomerCode as 'CustCode(10 Digit)', LastName as 'LName(18)',FirstName as 'Fname(18)',AccountNo as 'AccountNum(Max 20)',Currency as 'Currency(3)',AccountType as 'Account type(2)',CardProduct as 'Card Product(4)', Sex as 'Sex(1)',HomeCity as 'HomeCity(20)',MaritialStatus as 'Married(1)', MobileNo as 'Mobile No.(10)',Email as 'E-mail' from MasterTable where CreatedDate=@CreatedDate", connection);
command.Parameters.AddWithValue("@CreatedDate", dateTimePicker1.Text);
command.ExecuteNonQuery();
DataTable dtt = new DataTable();
SqlDataAdapter sdap = new SqlDataAdapter(command);
sdap.Fill(dtt);
dataGridView1.DataSource = dtt;
connection.Close();
答案 0 :(得分:-1)
只要您在选择查询中传递此内容即可。使用CASE
CASE WHEN Sex=0 then 'Female' WHEN Sex=1 then 'Male' END as Genderdisp