I have a controller that accepts a list of object then insert it to database I already done it but I think my code will have a problem if there will be a large of data.
My code
public void SaveAnswers(List<questionModel.SAVEDANSWER> answers, int userid)
{
string query = "INSERT INTO answer (QUESTIONID,USERANSWERID, USERID) VALUES (@qid, @aid,@uid);";
using (MySqlConnection myconn = new MySqlConnection(cmn.connstring))
{
myconn.Open();
for (int i = 0; i <= answers.Count - 1; i++)
using (MySqlCommand myCmd = new MySqlCommand(query, myconn))
{
myCmd.CommandType = System.Data.CommandType.Text;
MySqlParameter questionid = myCmd.Parameters.AddWithValue("@qid", answers[i].QUESTIONID);
myCmd.Parameters.AddWithValue("@qid", answers[i].QUESTIONID);
myCmd.Parameters.AddWithValue("@aid", answers[i].ANSWERID);
myCmd.Parameters.AddWithValue("@uid", userid);
myCmd.ExecuteNonQuery();
}
myconn.Close();
myconn.Dispose();
}
}
I did something similar in my SQL Server. I inserted the list of object to data table then pass the data table to the stored procedure.
In my stored procedure in SQL Server, I have a table parameter.
Can I do something like that in MySQL?