如何在这里添加外键?希望你能帮助我
public bool AddMedicinePrescription(string Generic, string Brand, string ContainerNum, string MedtoStore, string status)
{
sqlstring = "INSERT INTO hdmedicine (GenericName, BrandName, ContainerNumber, Quantity,Status )" + "VALUE ('" + Generic + "', '" + Brand + "', " + ContainerNum + ", " + MedtoStore + ", '"+ status +"')";
try
{
connect.Open();
MySqlCommand cmd = new MySqlCommand(sqlstring, connect);
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
connect.Close();
return true;
最佳答案
您不能使用 1 个 sql 插入语句插入到2 个表。
但是,您可以使用以下选项
使用 Entity Framework ,您可以创建链接在一起的实体。由于概念模型是一组类,因此对 EF 实体执行 CRUD(创建、读取、更新和删除)操作要简单得多。
创建一个存储过程并插入存储过程中的 2 个表。
关于c# - 在#mysql中使用外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35097833/