大家帮忙看看。想给mysql数据库插入一条信息,发现执行后数据库里有一条信息,但这条信息只有主键id,其他信息进不去。MySqlDataAdapter da = new MySqlDataAdapter();
DataSet ds = new DataSet(); String connStr="server=localhost;userid=root;password=;database=jeff";
MySqlConnection conn=new MySqlConnection(connStr);
MySqlCommand selectCmd = new MySqlCommand("select * from score",conn);
MySqlCommand insertCmd = new MySqlCommand("insert into score(scname,scsubject,scscore) values(@scname,@scsubject,@scscore)",conn);
insertCmd.Parameters.Add("@scname", MySqlDbType.VarChar, 20, "scname");
insertCmd.Parameters.Add("@scsubject", MySqlDbType.VarChar, 20, "scsubject");
insertCmd.Parameters.Add("@scscore", MySqlDbType.Int16, 11, "scscore");
da.SelectCommand = selectCmd;
da.InsertCommand = insertCmd;
da.Fill(ds, "score");
DataRow dataRow = ds.Tables["score"].NewRow();
dataRow["scname"] = "阿明";
dataRow["scsubject"] = "数学";
dataRow["scscore"] = "98";
ds.Tables["score"].Rows.Add(dataRow); da.Update(ds,"score");
GridView1.DataSource = ds.Tables["score"];
GridView1.DataBind();
DataSet ds = new DataSet(); String connStr="server=localhost;userid=root;password=;database=jeff";
MySqlConnection conn=new MySqlConnection(connStr);
MySqlCommand selectCmd = new MySqlCommand("select * from score",conn);
MySqlCommand insertCmd = new MySqlCommand("insert into score(scname,scsubject,scscore) values(@scname,@scsubject,@scscore)",conn);
insertCmd.Parameters.Add("@scname", MySqlDbType.VarChar, 20, "scname");
insertCmd.Parameters.Add("@scsubject", MySqlDbType.VarChar, 20, "scsubject");
insertCmd.Parameters.Add("@scscore", MySqlDbType.Int16, 11, "scscore");
da.SelectCommand = selectCmd;
da.InsertCommand = insertCmd;
da.Fill(ds, "score");
DataRow dataRow = ds.Tables["score"].NewRow();
dataRow["scname"] = "阿明";
dataRow["scsubject"] = "数学";
dataRow["scscore"] = "98";
ds.Tables["score"].Rows.Add(dataRow); da.Update(ds,"score");
GridView1.DataSource = ds.Tables["score"];
GridView1.DataBind();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货