我目前正致力于通过Web服务获取学生信息并将其保存到数据库的任务。我已经成功实现了添加单个学生信息的任务,但我想在运行时使用相同的Web方法添加多个学生。
以下是代码:
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;
}