我自己写了个Web service,用的是SQL SERVER2005数据库,然而当我新建另一个数据库后,把Web service中的与数据库有关的代码更改后,访问这个新建的数据库却总是报如下错误关键字 'user' 附近有语法错误。user是我在新数据库里新建的一张表。数据库权限问题已经排除,因为所有数据库的权限我都设为一样的。我的代码如下:
public bool login(string username, string userpassword)
{
bool b = false;
string connstr = "Data Source=ANDY;Initial Catalog=eve;Integrated Security=True";
SqlConnection conn = new SqlConnection(connstr);
SqlCommand comm = new SqlCommand("select * from user where name=@name and pwd=@password", conn);
comm.Parameters.Add("name", SqlDbType.VarChar);
comm.Parameters.Add("password", SqlDbType.VarChar);
comm.Parameters["name"].Value = username;
comm.Parameters["password"].Value = userpassword;
if(conn.State==ConnectionState.Closed)
{
conn.Open();
MessageBox.Show("hao");
}
SqlDataReader result = comm.ExecuteReader();
if (result.Read() == true)
{ b = true; }
result.Close();
conn.Close();
return b;
}就是换了数据库,就不能访问了。
public bool login(string username, string userpassword)
{
bool b = false;
string connstr = "Data Source=ANDY;Initial Catalog=eve;Integrated Security=True";
SqlConnection conn = new SqlConnection(connstr);
SqlCommand comm = new SqlCommand("select * from user where name=@name and pwd=@password", conn);
comm.Parameters.Add("name", SqlDbType.VarChar);
comm.Parameters.Add("password", SqlDbType.VarChar);
comm.Parameters["name"].Value = username;
comm.Parameters["password"].Value = userpassword;
if(conn.State==ConnectionState.Closed)
{
conn.Open();
MessageBox.Show("hao");
}
SqlDataReader result = comm.ExecuteReader();
if (result.Read() == true)
{ b = true; }
result.Close();
conn.Close();
return b;
}就是换了数据库,就不能访问了。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货