2 m421299142 m421299142 于 2014.03.05 19:33 提问

使用数据适配器离线访问数据库,下面这段代码老是出错!学生党求助!!

SqlDataAdapter da = new SqlDataAdapter();
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
SqlConnection conn = new SqlConnection("server=(local);database=超市会员管理;trusted_connection=true");
SqlCommand selectcomm = new SqlCommand("select * from member", conn);
SqlCommand insertcomm = new SqlCommand("insert into member values(@cid,@cname,@password,@age,@gender,@workplace,@phonenumber)", conn);
insertcomm.Parameters.Add("@cid", SqlDbType.NChar, 50, "cid");
insertcomm.Parameters.Add("@cname", SqlDbType.NVarChar, 50, "cname");
insertcomm.Parameters.Add("@password", SqlDbType.NVarChar, 50, "password");
insertcomm.Parameters.Add("@age", SqlDbType.Int, 50, "age");
insertcomm.Parameters.Add("@gender", SqlDbType.NVarChar, 50, "gender");
insertcomm.Parameters.Add("@workplace", SqlDbType.NVarChar, 50, "workplace");
insertcomm.Parameters.Add("@phonenumber", SqlDbType.NVarChar, 50, "phonenumber");
da.SelectCommand = selectcomm;

da.InsertCommand = insertcomm;
DataSet ds=new DataSet();
da.Fill(ds, "member");
DataRow row = ds.Tables["member"].NewRow();
row["cid"] = TextBox1.Text;
row["cname"] = TextBox2.Text;
row["password"] = TextBox3.Text;
row["age"] = Convert.ToInt32( TextBox4.Text);
row["gender"] = TextBox5.Text;
row["workplace"] = TextBox6.Text;
row["phonenumber"] = TextBox7.Text;
ds.Tables["member"].Rows.Add(row);
da.Update(ds,"member");

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!