不能在一个表中插入值

本文关键字:插入 一个 不能 | 更新日期: 2023-09-27 17:49:17

我有一个问题,当它涉及到插入表我有表格Personaldata和Spouse

在配偶表中插入语句正在运行。但是,我不能在表中插入Personaldata。

请帮帮我。

下面是我的代码:

  private void button2_Click(object sender, EventArgs e)
   {
           personalConn.Open();
           oleDbCmd.Connection = personalConn;
       oleDbCmd.CommandText = "insert into Personaldata(Bloclno,Lotno,Numberofoccupants,Firstname,Familyname,Dateofbirth,Age,Bloodtype,Placeofbirth,Religion) values ('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.textBox4.Text + "','" + this.textBox5.Text + "','" + this.textBox6.Text + "','" + this.textBox7.Text + "','" + this.textBox8.Text + "','" + this.textBox9.Text + "','" + this.textBox10.Text + "');";
       oleDbCmd.CommandText = "insert into Spouse(Firstname,Familyname,Dateofbirth,Age,Bloodtype,Placeofbirth,Religion,Startofoccupancy,Contactnumber,NumberofChildren,Numberofdogs, Vaccinatedwithantirabies) values ('" + this.textBox11.Text + "','" + this.textBox12.Text + "','" + this.textBox21.Text + "','" + this.textBox13.Text + "','" + this.textBox14.Text + "','" + this.textBox15.Text + "','" + this.textBox16.Text + "','" + this.textBox17.Text + "','" + this.textBox18.Text + "','" + this.textBox22.Text + "','" + this.textBox25.Text + "','" + this.textBox19.Text + "');";

       int temp = oleDbCmd.ExecuteNonQuery();

不能在一个表中插入值

你可以这样做…设置CommandText,然后执行它,然后设置另一个CommandText,然后再次执行!

personalConn.Open();
oleDbCmd.Connection = personalConn;
int temp;
oleDbCmd.CommandText = "insert into Personaldata(Bloclno,Lotno,Numberofoccupants,Firstname,Familyname,Dateofbirth,Age,Bloodtype,Placeofbirth,Religion) values ('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.textBox4.Text + "','" + this.textBox5.Text + "','" + this.textBox6.Text + "','" + this.textBox7.Text + "','" + this.textBox8.Text + "','" + this.textBox9.Text + "','" + this.textBox10.Text + "');";
temp = oleDbCmd.ExecuteNonQuery();
oleDbCmd.CommandText = "insert into Spouse(Firstname,Familyname,Dateofbirth,Age,Bloodtype,Placeofbirth,Religion,Startofoccupancy,Contactnumber,NumberofChildren,Numberofdogs, Vaccinatedwithantirabies) values ('" + this.textBox11.Text + "','" + this.textBox12.Text + "','" + this.textBox21.Text + "','" + this.textBox13.Text + "','" + this.textBox14.Text + "','" + this.textBox15.Text + "','" + this.textBox16.Text + "','" + this.textBox17.Text + "','" + this.textBox18.Text + "','" + this.textBox22.Text + "','" + this.textBox25.Text + "','" + this.textBox19.Text + "');";
temp = oleDbCmd.ExecuteNonQuery();
 string cT = "insert into Personaldata(Bloclno,Lotno,Numberofoccupants,Firstname,Familyname,Dateofbirth,Age,Bloodtype,Placeofbirth,Religion) values ('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.textBox4.Text + "','" + this.textBox5.Text + "','" + this.textBox6.Text + "','" + this.textBox7.Text + "','" + this.textBox8.Text + "','" + this.textBox9.Text + "','" + this.textBox10.Text + "');"+
         "insert into Spouse(Firstname,Familyname,Dateofbirth,Age,Bloodtype,Placeofbirth,Religion,Startofoccupancy,Contactnumber,NumberofChildren,Numberofdogs, Vaccinatedwithantirabies) values ('" + this.textBox11.Text + "','" + this.textBox12.Text + "','" + this.textBox21.Text + "','" + this.textBox13.Text + "','" + this.textBox14.Text + "','" + this.textBox15.Text + "','" + this.textBox16.Text + "','" + this.textBox17.Text + "','" + this.textBox18.Text + "','" + this.textBox22.Text + "','" + this.textBox25.Text + "','" + this.textBox19.Text + "');";
oleDBCmd.CommandText = cT;
相关文章: