0

我编写了这个 c# 代码来从学生信息中选择 card_id,除了一个 card_id,但我从网上读到 except 子句在访问中不起作用……我该怎么做,请帮帮我?

ol_com.CommandText = "select [card_id] from student_info except select [card_id] from student_info where [card_id] = '"+update_st_card.Text+"'";
                reader = ol_com.ExecuteReader();
                if (reader.HasRows)
                {
                    up_st_lbl2.Text = "message";
                }
4

4 回答 4

3

我认为您不必要地进行复杂查询。

它可以很容易地使用NOT IN

ol_com.CommandText = "select [card_id] from student_info 
where [card_id] not in ('"+update_st_card.Text+"')";
于 2013-07-22T11:58:31.003 回答
1

您在插入时没有问题,所以要更新,请尝试这个简单的。update_st_card.Text 只有一个 card_Id。

ol_com.CommandText = "select [card_id] from student_info 
where [card_id] ='"+update_st_card.Text+"'";
reader = ol_com.ExecuteReader();
string str=string.Empty();
if (reader.HasRows)
{
  //Update here
    str="Update student_info set mobile_no='Your new value to set'
             where [card_id] ='"+update_st_card.Text+"'";

}
else
{
  //insert here
    str="Your Insert command";
}
ol_com.CommandText = str;
ol_com.ExecuteNonQuery();
于 2013-07-26T14:11:22.717 回答
0

我认为这将解决您的问题,我们可以不在任何地方使用访问、sql server、nhibernate

ol_com.CommandText = "select [card_id] from student_info where [card_id] not in ( select [card_id] from student_info where [card_id] = '"+update_st_card.Text+"'");
reader = ol_com.ExecuteReader();
if (reader.HasRows)
{
   up_st_lbl2.Text = "message";
}
于 2013-07-22T11:57:29.177 回答
0

我认为你可以使用 NOT IN

您的查询可以写成,

select [card_id] 
from student_info 
where [card_id] NOT IN 
 (select [card_id] from student_info where [card_id] = '"+update_st_card.Text+"'")
于 2013-07-22T11:57:44.577 回答