我想根据leavetype和emp id在textbox1
中显示emp离开余额。
我正在使用下面的代码,但它没有显示总休假余额。
private void cbleavetype_SelectedIndexChanged()
{
conn = new SqlConnection(@"Data Source=........")
conn.Open();
SqlCommand command = new SqlCommand("select leave from leaveallotment where id='" + comboBox1.Text + "' && leavetype='" + cbleavetype.Text + "'",conn);
SqlDataAdapter adp = new SqlDataAdapter(command);
DataTable tbl = new DataTable();
adp.Fill(tbl);
// Show total leave in textBox1
textBox1.Text = cbleavetype.SelectedValue.ToString();
}
答案 0 :(得分:0)
我认为需要做的一件事就是改变'&&'到'和'
答案 1 :(得分:-1)
您可以使用以下代码段
connectionString.Open();
SqlCommand command =
new SqlCommand(
"select LeaveCount from leaveallotment where
id= '" + comboBox1.Text + "' and
leavetype='" + comboBox2.Text + "'",
connectionString);
SqlDataReader da = command.ExecuteReader();
if (da.Read()) {
textBox1.Text = da["LeaveCount"].ToString();
}
connectionString.Close();