C#中怎么降多个文本框的数据存入SQL2005数据库

2024-12-23 08:30:35
推荐回答(2个)
回答1:

var s1 = txt1.Text;
var s2 = txt2.Text;
var s3 = txt3.Text;
var s4 = txt4.Text;
var s5 = txt5.Text;
var s6 = txt6.Text;
var s7 = txt7.Text;
var sql = string.Format("insertnto 表(a,b,c,d,e,f,g) values '{0}','{1}','{2}','{3}','{4}','{5}','{6}' ",s1,s2,s3,s4,s5,s6,s7);
sqlCommand.CommandText = sql;
sqlCommand.ExecuteNonQuery();

回答2:

insert into table(字段1,字段2,字段3) values('"+textBox1.Text+","+textBox2.Text+","+textBox3.Text+"');