我总是会出现这样的错误,不知道哪里出了问题?
异常详细信息:System.Data.SqlClient.SqlException:在关键字"user"附近有语法错误
private void DBOpen()
{
strConnectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
conn = new SqlConnection(strConnectionString);
conn.Open();
}
public void DataGridBind()
{
string strsql="select user_id,username,sex,hometown,mobilephone,xueli,dep_name,zhiwu from user,dep where user.dep_id=dep.dep_id";
ds = new DataSet();
DBOpen();
da =new SqlDataAdapter(strsql,conn);
da.Fill(ds,"User"); //出错!!!
DataView dv = ds.Tables[0].DefaultView;
show_person.DataSource = dv;
show_person.DataBind();
conn.Close();
}
Web.config中代码:
<appSettings>
<!--
设置数据库连接字符串配置
-->
<add key="ConnectionString" value="server=MY-TOMATO;database=manage;uid=administrator;pwd=123" />
</appSettings>