I am currently working on a task which takes student information through web service and saves it to database. I have successfully implemented the task for adding single student information, but I want to add multiple students at runtime using the same web method.
Here is the code:
public string insertStudent(int id,string f_name , string l_name)
{
var con = new SqlConnection(ConnectionState());
con.Open();
string insert = "INSERT INTO STUDENT(std_id, first_name,last_name)";
//var cmd = new SqlCommand("Insert into [Student](std_id,first_name, last_name,) values('" + id + "','" + f_name + "','" + l_name+ "')", con);
insert += " VALUES (";
insert += "'" + id + "'";
insert += ", '" + f_name + "'";
insert += ", '" + l_name + "'";
insert += ")";
var cmd = new SqlCommand(insert, con);
cmd.ExecuteNonQuery();
string result = "Data Added to Database";
con.Close();
return result;
}