sqlInsertCommand1.CommandText="INSERT INTO 用户表 VALUE('"+textBxo1.tText"',+'"textBox2.Text+"')"如果字段为数字的话,把'去掉 sqlInsertCommand1.CommandText="INSERT INTO 用户表 VALUE("+textBxo1.tText",+"textBox2.Text+")"
上面的错了,不好意思sqlInsertCommand1.CommandText="INSERT INTO 用户表 VALUE('"+textBxo1.tText+"','"+textBox2.Text+"')"如果字段为数字的话,把'去掉 sqlInsertCommand1.CommandText="INSERT INTO 用户表 VALUE("+textBxo1.tText+","+textBox2.Text+")"
1点提交的之前你是否在LOAD里面单独设置过textbox1="",而没有写在ispostback里面
2:最好还是把SQL语句写全
insert into yonghu(字段1,字段2) values (textbox,textbox2)
cmd=new SqlCommand("insert into info (name,phone) values(@name,@phone)",cn);
cmd.Parameters.Add("@name",SqlDbType.VarChar,50);
cmd.Parameters.Add("@phone",SqlDbType.VarChar,10);
cmd.Parameters[0].Value=textBox1.tText;
cmd.Parameters[1].Value=textBox2.Text;
cmd.ExecuteNonQuery();
private void button1_Click(object sender, System.EventArgs e)
{
sqlConnection1.Open();
if(textBox2.Text==textBox3.Text)
{
sqlInsertCommand1.CommandText="INSERT INTO (用户) VALUES('" + textBox1.Text + "','" + textBox1.Text + "')";
}
Form1 xian1=new Form1();
this.Hide();
xian1.Show();
}
这样添加不了.
cmd.executenoquote();
sqlInsertCommand1.CommandText="INSERT INTO 用户表 VALUE("+textBxo1.tText",+"textBox2.Text+")"
sqlInsertCommand1.CommandText="INSERT INTO 用户表 VALUE("+textBxo1.tText+","+textBox2.Text+")"
设置断点,取出sql语句的内容
到数据库里直接执行你的语句,如果插入成功,则说明你的sql语句无错误,再看看其他的地方有什么问题
要作字串带进去才行string.Format("INSERT TABELNAME VALUES('{0}', '{1}')", textBox1.Text, textBox2.Text)指定CommandText属性,注意要把Connection.Open()才行
SqlCommand Cmd_ins=new SqlCommand(Sel_ins,myConnection);
Cmd_ins.Parameters.Add(new SqlParameter("@ID",SqlDbType.Int,4));
Cmd_ins.Parameters["@id"].Value =Max_num;
Cmd_ins.Parameters.Add(new SqlParameter("@username",SqlDbType.VarChar,16));
Cmd_ins.Parameters["@username"].Value =username.Text;
Cmd_ins.Parameters.Add(new SqlParameter("@password",SqlDbType.VarChar,16));
Cmd_ins.Parameters["@password"].Value =password1.Text;
Cmd_ins.Parameters.Add(new SqlParameter("@oskey",SqlDbType.VarChar,5));
Cmd_ins.Parameters["@oskey"].Value =oskey.SelectedValue;
Cmd_ins.Parameters.Add(new SqlParameter("@lastlogin",SqlDbType.DateTime,8));
Cmd_ins.Parameters["@lastlogin"].Value =currentTime;
//执行
Cmd_ins.ExecuteNonQuery();
sqlInsertCommand1.ExecuteNonQuery();
应该可以的吧。试试