初学C#,帮我看看这个SQL语句有什么问题
SqlCommand sqlcom = new SqlCommand();sqlcom.Connection = sqlconn;
sqlcom.CommandText = "INSERT INTO User(UserName,NickName,RealName,Birthday,qq,Eemail,Photo,SpaceUrl,Msn,LastLoginTime,Intruduce,Score,UserStatus,UserLock,UserOnlineTime,UserLevel,UserTypeId,Sex,RegisterTime,Professional)
VALUES( @UserName,@NickName,@RealName,@Birthday,@qq,@Email,@Photo,@SpaceUrl,@Msn,@LastLoginTime,@Intruduce,@Score,@UserStatus,@UserLock,@UserOnlineTime,@UserLevel,@UserTypeId,@Sex,@RegisterTime,@Professional)";
sqlcom.Parameters.AddWithValue("@UserName", TextBox1.Text);
sqlcom.Parameters.AddWithValue("@NickName", TextBox2.Text);
sqlcom.Parameters.AddWithValue("@RealName", TextBox3.Text);
sqlcom.Parameters.AddWithValue("@Birthday", TextBox7.Text);
sqlcom.Parameters.AddWithValue("@qq", TextBox6.Text);
sqlcom.Parameters.AddWithValue("@Email", TextBox8.Text);
sqlcom.Parameters.AddWithValue("@SpaceUrl", "");
sqlcom.Parameters.AddWithValue("@Msn","");
sqlcom.Parameters.AddWithValue("@LastLoginTime",null);
sqlcom.Parameters.AddWithValue("@Photo", FileUpload1.FileName);
sqlcom.Parameters.AddWithValue("@Score", 0);
sqlcom.Parameters.AddWithValue("@UserStatus", "offline");
sqlcom.Parameters.AddWithValue("@UserLock", 0);
sqlcom.Parameters.AddWithValue("@UserOnlineTime","");
sqlcom.Parameters.AddWithValue("@UserLevel", 0);
sqlcom.Parameters.AddWithValue("@UserTypeId",1);
sqlcom.Parameters.AddWithValue("@RegisterTime", DateTime.Now);
sqlcom.Parameters.AddWithValue("@Professional", "");
sqlcom.Parameters.AddWithValue("@Intruduce", TextBox9.Text);
sqlcom.Parameters.AddWithValue("@Password", TextBox4.Text);
sqlcom.Parameters.AddWithValue("@Sex", DropDownList1.Text);
运行时提示关键字User附近有错误 --------------------编程问答-------------------- User (UserName
中间少空格 --------------------编程问答-------------------- 不行,提示:出错:关键字 'User' 附近有语法错误。 --------------------编程问答-------------------- 空格加了,还是不行 --------------------编程问答-------------------- 建议在sql中测试一下插入代码。 --------------------编程问答-------------------- 对照一下User表字段名字有无写错
大小写之类的 --------------------编程问答-------------------- 试试
INSERT INTO [User]
如果每一个列都插入值可以省略下面这一行,直接写values()/*(UserName,NickName,RealName,Birthday,qq,Eemail,Photo,SpaceUrl,Msn,LastLoginTime,Intruduce,Score,UserStatus,UserLock,UserOnlineTime,UserLevel,UserTypeId,Sex,RegisterTime,Professional) */
--------------------编程问答-------------------- 试试打下断点贴下错误吧....
--------------------编程问答-------------------- Eemail
sqlcom.Parameters.AddWithValue("@Password", TextBox4.Text);
command语句里没有Password字段???
需要仔细检查大小写拼写和字段名称的对应 --------------------编程问答--------------------
"INSERT INTO User(UserName,NickName,RealName,Birthday,qq,Eemail,Photo,SpaceUrl,Msn,LastLoginTime,Intruduce,Score,UserStatus,UserLock,UserOnlineTime,UserLevel,UserTypeId,Sex,RegisterTime,Professional)
VALUES( @UserName,@NickName,@RealName,@Birthday,@qq,@Email,@Photo,@SpaceUrl,@Msn,@LastLoginTime,@Intruduce,@Score,@UserStatus,@UserLock,@UserOnlineTime,@UserLevel,@UserTypeId,@Sex,@RegisterTime,@Professional)";
Email --------------------编程问答-------------------- 好了,EMAIL有错,还有个列名标错了,谢谢各位 --------------------编程问答-------------------- DataContext 能让你轻松点 --------------------编程问答-------------------- --------------------编程问答-------------------- 找到错误就好。
--------------------编程问答-------------------- 表名user 是关键字,要用[]包起来吧 --------------------编程问答-------------------- 14楼正解,有些事关键字,用【】来处理吧 --------------------编程问答--------------------
估计是这问题.
--------------------编程问答-------------------- INSERT INTO [User](UserName,NickName,RealName,Birthday,qq,Eemail,Photo,SpaceUrl,Msn,LastLoginTime,Intruduce,Score,UserStatus,UserLock,UserOnlineTime,UserLevel,UserTypeId,Sex,RegisterTime,Professional) ... --------------------编程问答--------------------
insert into [User]...........--------------------编程问答-------------------- 楼上都是正解,但温馨提示下:user在SQL里是关键字,LZ最好拿[]括起来。 --------------------编程问答--------------------
INSERT INTO User(UserName,NickName,RealName,Birthday,qq,Eemail,Photo,SpaceUrl,Msn,LastLoginTime,Intruduce,Score,UserStatus,UserLock,UserOnlineTime,UserLevel,UserTypeId,Sex,RegisterTime,Professional)
VALUES( @UserName,@NickName,@RealName,@Birthday,@qq,@Email,@Photo,@SpaceUrl,@Msn,@LastLoginTime,@Intruduce,@Score,@UserStatus,@UserLock,@UserOnlineTime,@UserLevel,@UserTypeId,@Sex,@RegisterTime,@Professional)";
sqlcom.Parameters.AddWithValue("@Password", TextBox4.Text);
我确信楼主少个password参数、但是这跟楼主的错误提示没有关系 --------------------编程问答--------------------
补充:.NET技术 , C#