对于SQLSERVER数据库和ACCESS数据库,首先是连接字符串不同,其次是SQL语句的问题,一般在SQLSERVER中通过的SQL在ACCESS中不一定通过,但在ACCESS中通过的SQL在SQLSERVER中一定能通过。另外,在.NET中,可以通过OLEDB的类连接任何支持ODBC的数据库,但连接SQLSERVE时最好使用SQLCLIENT的类(在1.1中还增加了ORACLE、DB2等的支持)最后,同样的SQLSERVER连接字符串,OLEDB和SQLCLIENT中是不同的。
调试欢乐多
string myconn="server=abc;uid=sa;pwd=sa;database=zxbm";
string strcmd="select count(*) from account where (user like'"+TextBox1.Text+"'and pwd like'"+TextBox2.Text+"')";
SqlConnection MyConn=new SqlConnection (myconn);
SqlCommand odb=new SqlCommand(strcmd,MyConn);
odb.Connection .Open ();
//SqlDataReader olerd=odb.ExecuteScalar ();
int flag=(int)odb.ExecuteScalar ();
if (flag>0 )
{
Session["user"]=TextBox1.Text ;
Response.Redirect ("zxbm1.aspx");
}
else
{
Label2.Text ="sorry,user is not exist!";
TextBox1.Text ="";
TextBox2.Text ="";
}
MyConn.Close ();
like语句中access要用"*",而sql要用"%",检查一下sql语句