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();
但是就是不能把记录保存到数据库中
哪里有问题啊!
请各位帮帮忙 谢谢!
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();
但是就是不能把记录保存到数据库中
哪里有问题啊!
请各位帮帮忙 谢谢!
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 ()+"')
以下帖子给分。
如何在C#.net WEB2005开发中获取dropdownlist在网页中的位置坐标?
http://community.csdn.net/Expert/topic/5481/5481151.xml?temp=.4136316
救救我。
以下帖子给分。
如何在C#.net WEB2005开发中获取dropdownlist在网页中的位置坐标?
http://community.csdn.net/Expert/topic/5580/5580708.xml?temp=.7489435
昨天晚上发错连接,更正在发送。
INSERT INTO studentTable
(studentId, studentName, password, roomNumber, telephone, QQ, studentSex,
[E-Mail])
VALUES (@studentId, @studentName, @password, @roomNumber, @telephone, @QQ,
@studentSex, @E - Mail)
保存按钮的代码是
private void Button1_Click(object sender, System.EventArgs e)
{
conn.Open();
cmd.Parameters.Add("@studentId","'" + txtstuId.Text.Trim() + "'");
cmd.Parameters.Add("@studentName","'" + txtstuName.Text.Trim() + "'");
cmd.Parameters.Add("@password","'" + txtPassword.Text.Trim() + "'");
cmd.Parameters.Add("@roomNumber","'" + txtroomNumber.Text.Trim() + "'");
cmd.Parameters.Add("@telephone","'" + txtTelephone.Text.Trim() + "'");
cmd.Parameters.Add("@QQ","'" + txtQQ.Text.Trim() + "'");
cmd.Parameters.Add("@studentSex","'" + DropDownList1.SelectedValue + "'");
cmd.Parameters.Add("@E-Mail","'" + txtMail.Text.Trim() + "'");
cmd.ExecuteNonQuery();
conn.Close();
}记录还是保存不到数据库,我打开事件探查器看 根本就不执行 update 语句
是什么原因阿?
大家再帮忙看看!谢谢!
你加那些单引号多余 这里不是加到sql语句 而是参数赋值
cmd.Parameters.Add("@UserName",this.txtUser.Text);
cmd.Parameters.Add("@Password",this.txtPwd.Text);
try
{
cn.Open();
cmd.ExecuteNonQuery();
ds.Clear();
da.Fill(ds,"Users");
MessageBox.Show("修改成功!");
this.txtUser.Clear();
this.txtPwd.Clear();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
cn.Close();
}