大家好 我有段登录的代码 可老在下面代码的最后一句 提示 “未处理的“System.Data.SqlClient.SqlException”类型的异常出现在 system.data.dll 中。”怎么回事啊?代码应该没有问题吧?我是VS2003+SQLSERVER
System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection("server=127.0.0.1;database=test;uid=sa;pwd=123;");
string sql = "select * from user";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql,con);
con.Open();
System.Data.SqlClient.SqlDataReader set1 =  cmd.ExecuteReader();//就这句提示错误
if(set1.Read())
...............................
谢谢大家了 以前B/S做的多 C/S下做的不多

解决方案 »

  1.   

    string sql = "select * from [User]";
      

  2.   

    一楼的可能是对的,User好象是关键字
      

  3.   

    user是方法名,所以sql的编译器看见有这个字就将其视为user()方法,因此出错了
      

  4.   

    string sql="select * from [user]";
    就可以了
      

  5.   

    可以在Form的Load事件里查询,在查询前使用窗体类名.DoEvent()方法来同步调用就看不出卡的效果了
      

  6.   

    以后啊,不要用USER了,我第一次用它的时候,就是出错,可是又不知道怎么回事,后来才懂的,以后啊,我都加上数据库的前缀
      

  7.   

    7楼的朋友 我怎么没看到DoEvent()方法啊 能说的具体些吗?谢谢