C#insert数据库问题
insert成功,返回值为1,但是数据库表中没有
开发工具vs11+sql sever 2010rc0
链接:
public partial class regist : Form
{
string ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\data.mdf;Integrated Security=True";
public regist()
按钮事件:
private void button1_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
int i;
string cmd = "insert into users (userid,password,username,usersex,userage,usercall) values(";
cmd += "N'" + this.textBox1.Text + "',";
cmd += "N'" + this.textBox2.Text + "',";
cmd += "N'" + this.textBox4.Text + "',";
cmd += "N'" + this.comboBox1.Text + "',";
cmd += "" + Convert.ToInt32(this.textBox5.Text) + ",";
cmd += "" + Convert.ToInt32(this.textBox6.Text) + ")";
SqlCommand mycmd = new SqlCommand(cmd, conn);
i=mycmd.ExecuteNonQuery();
conn.Close();
if(i>0)
MessageBox.Show(i.ToString());
}
}
------解决方案--------------------
探讨 引用: 断点看看CMD的语句是什么,然后拿到数据库中去执行。 试过了,成功的
------解决方案--------------------
按钮事件:以下的代码没有问题,电话号码不要转成int类型...