Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法在1个表中插入值_C# - Fatal编程技术网

C# 无法在1个表中插入值

C# 无法在1个表中插入值,c#,C#,我在插入表格时遇到了一个问题 我有个人资料和配偶 表中的Insert语句正在运行。但是,我无法在表中插入个人数据 请帮帮我 这是我的密码: private void button2_Click(object sender, EventArgs e) { personalConn.Open(); oleDbCmd.Connection = personalConn; oleDbCmd.CommandText = "insert

我在插入表格时遇到了一个问题 我有个人资料和配偶

表中的Insert语句正在运行。但是,我无法在表中插入个人数据

请帮帮我

这是我的密码:

  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();

您收到了什么错误消息?这不是C代码。是C。如果你知道你在用什么语言工作,也许效果会更好。:-你能说得更具体些吗?它不起作用不是对问题的有效描述。它以什么方式不起作用?你收到错误信息了吗?它不编译吗?配偶会说哦,不,你不会吧!?如果你需要帮助,请具体说明你遇到的问题。我们在这里看不到你的屏幕也看不到你的心思,因此,我们只知道您告诉我们的内容。@KenWhite是的,您的评论中提到了它的CA。您需要向我们提供错误文本并提供问题的更多详细信息。您还应该使用参数化查询,否则您将面临SQL注入攻击。先生**@Tun Zarni Kyaw*非常感谢。。最后,它成功了:如果它成功了,把这个作为公认的答案,你会得到+2的声誉。怎么做,先生?我是新来的在答案的左侧,在上下投票按钮下有一个勾号符号。。。只需点击勾号并将其变为绿色OK先生谢谢。。先生,为什么我不能再发问题了?我该怎么办?
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();