Sql选择语句不工作WPF
本文关键字:工作 WPF 语句 选择 Sql | 更新日期: 2023-09-27 18:13:53
我正在一个WPF工作,我有一个sql语句连接到数据库。该语句是搜索First_Quater,它做,但当我改变到Second_Quater(这不是在数据库中),它会给我First_Quater的数字。我不能让它只在列中添加first_quarter。
我已经尝试了很多,搜索了互联网,但我仍然茫然。谢谢你的帮助。
SqlConnection con = new SqlConnection("Data Source=; Initial Catalog=; Integrated Security=True; Trusted_Connection=yes");
con.Open();
String comboquery = (@"SELECT * FROM [taxi_comm] WHERE First_Quarter = '" + checkedListBox1.SelectedItem + "'");
SqlCommand cmd = new SqlCommand(comboquery, con);
SqlDataReader dr = cmd.ExecuteReader();
double sum = 0;
for (int i = 0; i < gvDisplay.Rows.Count; ++i)
{
switch (checkedListBox1.SelectedItem.ToString().Trim())
{
case "First Quarter":
foreach (string s in checkedListBox1.CheckedItems)
{
sum += Convert.ToInt32(gvDisplay.Rows[i].Cells[10].Value);
txtTotalGST.Text = sum.ToString();
}
MessageBox.Show("Its feb");
break;
case "Second Quarter":
foreach (string st in checkedListBox1.CheckedItems)
{
sum += Convert.ToInt32(gvDisplay.Rows[i].Cells[10].Value);
txtTotalGST.Text = sum.ToString();
MessageBox.Show("You have reached the second quarter");
}
break;
您需要从查询
填充您的gvdisplay SqlCommand cmd = new SqlCommand(comboquery, con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable gvdisplay = new DataTable();
sda.Fill(gvdisplay);
double sum = 0;
for (int i = 0; i < gvdisplay.Rows.Count; ++i)
{
switch (checkedListBox1.SelectedItem.ToString().Trim())
{
case "First Quarter":
foreach (string s in checkedListBox1.CheckedItems)
{
sum += Convert.ToInt32(gvdisplay.Rows[i].Cells[10].Value);
txtTotalGST.Text = sum.ToString();
}
MessageBox.Show("Its feb");
break;
case "Second Quarter":
//.......//