日期:2014-05-18  浏览次数:20363 次

asp.net中向数据库保存数据问题
SQLCommand中的语句是
INSERT   INTO   studentTable
            (studentId,   studentName,   password,   roomNumber,   telephone,   QQ,   studentSex,  
            [E-Mail])
VALUES   ( '@studentId ',   '@studentName ',   '@password ',   '@roomNumber ',   '@telephone ',  
            '@QQ ',   '@studentSex ',   '@E-Mail ')
保存按钮的代码是
cmd.Parameters[ "@studentId "].Value   =   txtstuId.Text;
cmd.Parameters[ "@studentName "].Value   =   txtstuName.Text;
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
但是就是不能把记录保存到数据库中  
哪里有问题啊!
请各位帮帮忙     谢谢!


------解决方案--------------------
使用语句:cmd.Parameters.Add( "@studentId ",txtstuId.Text);
INSERT INTO studentTable
(studentId, studentName, password, roomNumber, telephone, QQ, studentSex,
[E-Mail])
VALUES (@studentId, @studentName, @password, @roomNumber, @telephone,
@QQ, @studentSex, @E-Mail)
@XXXX不需要用单引号就可以做了
还有你怎么就插两个字段?即使插两个字段你就应该在insert语句中就写两个 要不会和数据库冲突
------解决方案--------------------
找段正确的插入代码看看吧,你这应该是参数错误
问题不大
给你一段代码吧.不是用参数的,我感觉方便一点
insert into userlogin (username,userpassword,usersex,usereducation,userschool) values( ' "+this.txtusername .Text .Trim ()+ " ', ' "+this.txtpassword .Text .Trim ()+ " ', ' "+this.sex + " ', ' "+this.dpdlistxueli .SelectedValue + " ', ' "+this.txtgraduate .Text .Trim ()+ " ')
------解决方案--------------------
使用命令参数,不要在参数名上加引号 '