使用外键更新表中的数据

使用外键更新表中的数据

本文介绍了使用外键更新表中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在通过c#widows表更新表中的数据时遇到问题我有2个表,与外键链接我没有找到任何查询2表的解决方案



i使用此代码进行简单更新

但是我想用外键更新2个表中的数据

所以请给我发送代码



i have a problem while updating data in tables through c# widows form i have 2 tables,linked with foreign key i didn't find any solution for query for 2 tables

i use this code for simple update
but i want to update data in 2 tables with foreign key
so plz send me that code

string myconnection = "datasource=127.0.0.1;port=3306;username=root;password=7621361";
MySqlConnection myconn = new MySqlConnection(myconnection);

MySqlCommand selectcommand = new MySqlCommand("insert into mydb.employee (idemployee,name,type) values ('"+this.textBox3.Text+"','"+this.textBox4.Text+"','"+this.textBox5.Text+"') ; " + "insert into mydb.emp_account(idemp_account,loan,bill,balance,total) values ( '" + this.textBox6.Text + "','" + this.textBox7.Text + "','" + this.textBox8.Text + "','" + this.textBox9.Text + "','" + this.textBox10.Text + "');", myconn);
MySqlDataReader myreaderr;


                try
                {
                    myconn.Open();
                    myreaderr = selectcommand.ExecuteReader();
                    MessageBox.Show("saved");
                    while (myreaderr.Read())
                    {
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

推荐答案



insert into mydb.employee (idemployee,name,type)
values ('"+this.textBox3.Text+"','"+this.textBox4.Text+"','"+this.textBox5.Text+"')





详细信息:



Detail:

insert into mydb.emp_account(idemp_account,loan,bill,balance,total)
values ( '" + this.textBox6.Text + "','" + this.textBox7.Text + "','" + this.textBox8.Text + "','" + this.textBox9.Text + "','" + this.textBox10.Text + "')





详细说明插入语句(emp_account)中有哪个外键到主表?

至少this.textBox3.Text(I假设employee.idemployee是主要的)应该详细插入到fullfill foreignkey约束(当然有适当的字段)。



如果你给予它会有很多答案关于这两个表及其字段的简短概述。



Where in the detail insert statement (emp_account) you have a foreign key to the master table?
At least this.textBox3.Text (I assume employee.idemployee is primary) should apear in detail insert to fullfill foreignkey constraint (with appropriate field of course).

It would help a lot to answer if you give a short overview about this two tables and there fields.


这篇关于使用外键更新表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 20:04