日期:2014-05-17 浏览次数:20745 次
public DataSet Insert_Datable()
{
SqlConnection con = new SqlConnection(Configuration.Conn);
SqlDataAdapter sdp = new SqlDataAdapter();
DataSet dt = new DataSet();
SqlCommand comm = new SqlCommand();
comm.Connection = con;
comm.CommandText = "select Names,Address,Pid,Image from Users";
sdp.SelectCommand = comm;//首先要指定selectitem,并且字段要指定清楚,和insert字段个数和名称一致
SqlCommandBuilder scom = new SqlCommandBuilder(sdp);
sdp.Fill(dt, "Users");
comm.CommandText = "Insert into Users values(@Pid,@Names,@Address,@Image)";
SqlParameter[] pars = new SqlParameter[] {
new SqlParameter("@Pid",SqlDbType.Int,4,"Pid")