积极答复者
与数据库连接是为什么报错说userID等无效

问题
-
public partial class frmUM : Form
{DataOperate DOperate = new DataOperate();
LogicOperate LOperate = new LogicOperate();
protected string SqlString = "select UserID as 用户编号, UserName as 用户姓名, UserPwd as 用户密码, UserRight as 用户权限, Cphone as 联系电话, Address as 联系地址 ";
protected string SqlTable = "tb_User";
protected int Judge;
public frmUM()
{
InitializeComponent();
}private void frmUM_Load(object sender, EventArgs e)
{
DataSet MyDataSet = DOperate.GetDataset(SqlString, SqlTable);
dgvClientInfo1.DataSource=MyDataSet.Tables[0];
if (MyDataSet.Tables[0].Rows.Count > 0)
tsbDel1.Enabled = true;
else
tsbDel1.Enabled = false;
答案
-
你数据库中定义某些列名恐怕是关键字(保留字),建议直接用方括号:
Select [UserId] as……,[UserName] as……
ASP.NET Forum
Other Discussion Forums
FreeRice Donate
Issues to report
Free Tech Books Search and Download- 已建议为答案 CaillenModerator 2014年9月15日 1:24
- 已标记为答案 CaillenModerator 2014年9月23日 10:16
-
>>DataSet MyDataSet = DOperate.GetDataset(SqlString, SqlTable);
OP应该是在DOperate.GetDataset这个方法中将字段名称和表名称拼接起来了
@小小秀才,
你应该调试一下你的代码,查看一下最终生成的SQL语句是什么,然后检查一下SQL语句是否有错误(直接在SSMS中执行以下看看就知道了)。或者直接通过SQL Profile查看一下执行语句,看一下最终执行的SQL语句问题应该很快就可以解决。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已编辑 CaillenModerator 2014年9月16日 2:19
- 已标记为答案 CaillenModerator 2014年9月23日 10:16
全部回复
-
你数据库中定义某些列名恐怕是关键字(保留字),建议直接用方括号:
Select [UserId] as……,[UserName] as……
ASP.NET Forum
Other Discussion Forums
FreeRice Donate
Issues to report
Free Tech Books Search and Download- 已建议为答案 CaillenModerator 2014年9月15日 1:24
- 已标记为答案 CaillenModerator 2014年9月23日 10:16
-
这个proposed是有问题的。
他根本原因是select语句不完整,后面缺了FROM table 那部分。
SQL中执行一个没有from的select语句,就会报这个错。
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UserID'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UserName'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UserPwd'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'UserRight'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Cphone'.
Msg 207, Level 16, State 1, Line 1
Invalid column name 'Address'. -
>>DataSet MyDataSet = DOperate.GetDataset(SqlString, SqlTable);
OP应该是在DOperate.GetDataset这个方法中将字段名称和表名称拼接起来了
@小小秀才,
你应该调试一下你的代码,查看一下最终生成的SQL语句是什么,然后检查一下SQL语句是否有错误(直接在SSMS中执行以下看看就知道了)。或者直接通过SQL Profile查看一下执行语句,看一下最终执行的SQL语句问题应该很快就可以解决。
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已编辑 CaillenModerator 2014年9月16日 2:19
- 已标记为答案 CaillenModerator 2014年9月23日 10:16