C# 如何选择一列中除一个值以外的所有数据?

C# 如何选择一列中除一个值以外的所有数据?,c#,database,ms-access-2010,C#,Database,Ms Access 2010,我写这个c代码是为了从学生信息中选择卡片id,除了一个卡片id,但我从网上看到,except子句在access中不起作用。。。我该怎么做请帮帮我 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.

我写这个c代码是为了从学生信息中选择卡片id,除了一个卡片id,但我从网上看到,except子句在access中不起作用。。。我该怎么做请帮帮我

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";
                }

我认为这将解决您的问题,我们可以在anywhere Access、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";
}

我认为这将解决您的问题,我们可以在anywhere Access、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";
}

我想你可以用不在

您的查询可以写为

select [card_id] 
from student_info 
where [card_id] NOT IN 
 (select [card_id] from student_info where [card_id] = '"+update_st_card.Text+"'")

我想你可以用不在

您的查询可以写为

select [card_id] 
from student_info 
where [card_id] NOT IN 
 (select [card_id] from student_info where [card_id] = '"+update_st_card.Text+"'")

我认为你提出了一个不必要的复杂问题

它可以很容易地解决使用不在


我认为你提出了一个不必要的复杂问题

它可以很容易地解决使用不在


您在插入时没有问题,所以要更新,请尝试这个简单的。 更新卡片。文本仅具有一个卡片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();

您在插入时没有问题,所以要更新,请尝试这个简单的。 更新卡片。文本仅具有一个卡片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();


从学生信息中选择[card\u id],而不是[card\u id]=@cardd?请不要像您那样简单地连接sql语句。使用合适的参数?请告诉我如何使用参数?如果你看看我链接的页面,底部有一个例子。你使用什么数据库驱动程序?OleDb?ODBC?我使用OleDB驱动程序,谢谢你知道我理解它从学生信息中选择[card\u id],而不是[card\u id]=@cardd?请不要像您那样简单地连接sql语句。使用合适的参数?请告诉我如何使用参数?如果你看看我链接的页面,底部有一个例子。你使用什么数据库驱动程序?OleDb?ODBC?我使用OleDB驱动程序,谢谢你,我知道自从我使用Access以来,我一直理解它。它必须是x而不是y,x=y不是也可以吗+1对于不必要的复杂,顺便说一句,你的解决方案给我这个错误。。。In运算符中没有In查询表达式“[card_id]not In”123。您能提供错误详细信息吗?好的,它给出了此错误。。查看此链接,它是error@HunarA.Ahmad的图像,我忘记了括号。现在你能检查一下吗?我和Access合作很久了。它必须是x而不是y,x=y不是也可以吗+1对于不必要的复杂,顺便说一句,你的解决方案给我这个错误。。。In运算符中没有In查询表达式“[card_id]not In”123。您能提供错误详细信息吗?好的,它给出了此错误。。查看此链接,它是error@HunarA.Ahmad的图像,我忘记了括号。现在你能检查一下吗?我以前试过,但这不起作用。。。在所有的时间里,if语句都不是吗?我以前尝试过这个,但它不起作用。。。一直以来,if语句都不是?不,它不能解决我的问题,我以前试过这个。。。你的代码在最后的括号里有一个错误吗?不,它不能解决我的问题,我以前试过这个。。。您的代码在最后的括号中有错误吗?