Answer the question
In order to leave comments, you need to log in
How to add multiple database items using one query?
The database has a table in which you need to write 3 elements. Here is my code:
var recipe = Tbx_recipeName.Text;
var description = Tbx_recipeDescription.Text;
var instruction = Tbx_instructions.Text;
string sqlcom = $"INSERT INTO recipel VALUES (0, '{recipe}')";
string sqlcomm = $"INSERT INTO recipel VALUES (1, '{description}')";
string sqlcommand = $"INSERT INTO recipel VALUES (2, '{instruction}')";
using (MySqlCommand command = new MySqlCommand(sqlcom, connectToDB.connection))
command.ExecuteNonQuery();
using (MySqlCommand command = new MySqlCommand(sqlcomm, connectToDB.connection))
command.ExecuteNonQuery();
using (MySqlCommand command = new MySqlCommand(sqlcommand, connectToDB.connection))
connectToDB.CloseConnect();
string sqlcom = $"INSERT INTO recipel VALUES (0, '{recipe}'), (1, '{description}'), (2, '{instruction}')";
Answer the question
In order to leave comments, you need to log in
INSERT INTO tbl_name (a,b,c)
VALUES
(1,2,3),
(4,5,6),
(7,8,9);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question