我绑定的是 access 数据库
private void add()
{
OleDbConnection dltConn = new OleDbConnection();
dltConn.ConnectionString = strCon;
dltConn.Open();
string strInsert = "insert into dlt(qh,q1,q2,q3,q4,q5,h1,h2) VALUES ( ";
strInsert = strInsert + "" + Convert.ToInt32(textBox1.Text.Trim()) + ",";
strInsert = strInsert + "" + Convert.ToInt32(textBox2.Text.Trim()) + ",";
strInsert = strInsert + "" + Convert.ToInt32(textBox3.Text.Trim()) + ",";
strInsert = strInsert + "" + Convert.ToInt32(textBox4.Text.Trim()) + ",";
strInsert = strInsert + "" + Convert.ToInt32(textBox5.Text.Trim()) + ",";
strInsert = strInsert + "" + Convert.ToInt32(textBox6.Text.Trim()) + ",";
strInsert = strInsert + "" + Convert.ToInt32(textBox7.Text.Trim()) + ",";
strInsert = strInsert + "" + Convert.ToInt32(textBox8.Text.Trim()) + ",";
strInsert = strInsert + ")";
try
{
//这里是添加后 号码递增
textBox1.Text = (Convert.ToInt32(textBox1.Text) + 1).ToString();
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
OleDbCommand inst = new OleDbCommand(strInsert, dltConn);
inst.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show("添加失败,请检查是否有重名或者填写不全");
}
dltConn.Close();
refresh();
} |