日期:2014-05-17 浏览次数:20405 次
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();