How can i add foreign key here? Hope you can help me
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;
You can't insert into 2 tables using 1 sql Insert statement.
However, you can use following options
Using Entity Framework , you can create the entities which are linked together. It's much more simpler to perform CRUD (Create, Read, Update & Delete) operation on EF entities as conceptual model is set of classes.
Create a stored procedure and insert into 2 tables in the stored procedure.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.