谢谢,除了临时表,能不能用DATASET实现,下面是我做的单体实现主要的代码:
public void updateUsers(DataSet ds)
{
SqlCommand cmd = new SqlCommand("insert into employe(userid,username,sex,mobile_phone_no,identity_no,marry)values(@员工编号,@姓名,@性别,@手机,@身份证号,@婚否)", cn);
cmd.Parameters.Add("@员工编号", SqlDbType.Int,4, "userid");
cmd.Parameters.Add("@姓名",SqlDbType.NVarChar,20,"username");
cmd.Parameters.Add("@性别",SqlDbType.NVarChar,5,"sex");
cmd.Parameters.Add("@手机",SqlDbType.Decimal,9,"mobile_phone_no");
cmd.Parameters.Add("@身份证号", SqlDbType.NVarChar, 20, "identity_no");
cmd.Parameters.Add("@婚否", SqlDbType.NVarChar,2, "marry");
da = new SqlDataAdapter();
da.InsertCommand = cmd;
cn.Open();
da.Update(ds,ClassLibrary2.Class1.Table_User);
cn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
ClassLibrary1.Class1 dac = new ClassLibrary1.Class1();
DataSet ds = dac.getemploye();
DataRow dr = ds.Tables[0].NewRow();
dr["userid"] = this.TextBox2.Text;
dr["username"] = this.TextBox1.Text;
dr["sex"] = this.DropDownList2.Text;
dr["mobile_phone_no"] = this.TextBox11.Text;
dr["identity_no"] = this.TextBox6.Text;
dr["marry"] = this.DropDownList3.Text;
ds.Tables[0].Rows.Add(dr);
dac.updateUsers(ds);
bindData();
}
能不能通过更改这些代码完成批量添加,麻烦讲下如何实现