ASP.NET。提示报错:“关键字 'user' 附近有语法错误。” 大家帮我看看我的代码哪里有问题,感谢!
我是根据BookID=0001查找数据库book表中的UserID,然后根据查找出来的UserID再查找user表中的信息。大家帮我看看哪里有问题,万分感谢!!//Sql...
我是根据BookID=0001查找数据库book表中的UserID,然后根据查找出来的UserID再查找user表中的信息。大家帮我看看哪里有问题,万分感谢!!
// SqlCommand comm2 = new SqlCommand("select * from user where UserID='" + UserID + "'", conn);
//报错:关键字 'user' 附近有语法错误
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string bookID="0001";
string str = "Server=.;DataBase=warnier;User=sa;Password=521521";
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlCommand comm = new SqlCommand("select * from book where BookID='" + bookID + "'", conn);
SqlDataReader dr = comm.ExecuteReader();
string UserID=null;
if (dr.Read())
{
UserID = dr[2].ToString();
dr.Close();
}
SqlCommand comm2 = new SqlCommand("select * from user where UserID='" + UserID + "'", conn);
SqlDataReader dr2 = comm2.ExecuteReader();
if (dr2.Read())
{
Label8.Text = dr2[4].ToString();
}
dr2.Close();
conn.Close();
}
} 展开
// SqlCommand comm2 = new SqlCommand("select * from user where UserID='" + UserID + "'", conn);
//报错:关键字 'user' 附近有语法错误
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string bookID="0001";
string str = "Server=.;DataBase=warnier;User=sa;Password=521521";
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlCommand comm = new SqlCommand("select * from book where BookID='" + bookID + "'", conn);
SqlDataReader dr = comm.ExecuteReader();
string UserID=null;
if (dr.Read())
{
UserID = dr[2].ToString();
dr.Close();
}
SqlCommand comm2 = new SqlCommand("select * from user where UserID='" + UserID + "'", conn);
SqlDataReader dr2 = comm2.ExecuteReader();
if (dr2.Read())
{
Label8.Text = dr2[4].ToString();
}
dr2.Close();
conn.Close();
}
} 展开
2个回答
2014-12-23
展开全部
select * from dbo.[user] where UserID=0
user是系统表,最好加上[]
不太确定是不是这个问题,你可以试试
user是系统表,最好加上[]
不太确定是不是这个问题,你可以试试
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询