我正在尝试将数据网格中的行添加到mysql数据库中。我的问题是传递数据网格值
dt.Rows[i - 1][1] = dtgPo.Rows[i - 1].Cells["poCode"].Value.ToString();
到
cmd = new MySqlCommand("INSERT INTO poitems (poid,, poCode, itemCode, itemName) VALUES (?id,?pocode,?itemcode,?itemname)", coninsert);
希望你能帮帮我们。谢谢你们!
private void button3_Click(object sender, EventArgs e)
{
char pocode;
char itemcode;
char itemname;
int i;
MySqlDataAdapter da = new MySqlDataAdapter("SELECT * FROM poitems", coninsert);
MySqlCommandBuilder cb = new MySqlCommandBuilder(da);
DataTable dt = new DataTable();
da.Fill(dt);
for (i = 1; i < dtgPo.RowCount; i++)
{
MySqlDataAdapter da2 = new MySqlDataAdapter();
MySqlCommand cmd;
MySqlParameter parm;
// Create the SelectCommand.
dt.Rows[i - 1][1] = dtgPo.Rows[i - 1].Cells["poCode"].Value.ToString();
dt.Rows[i - 1][2] = dtgPo.Rows[i - 1].Cells["itemCode"].Value.ToString();
dt.Rows[i - 1][3] = dtgPo.Rows[i - 1].Cells["itemName"].Value.ToString();
cmd = new MySqlCommand("SELECT * FROM poitems", coninsert);
// Create the InsertCommand.
cmd = new MySqlCommand("INSERT INTO poitems (poid,, poCode, itemCode, itemName) VALUES (?id,?pocode,?itemcode,?itemname)", coninsert);
cmd.Parameters.Add("?id", MySqlDbType.Int16, 11, "poid");
cmd.Parameters.Add("?pocode", MySqlDbType.Int16, 11, "poCode");
cmd.Parameters.Add("?itemcode", MySqlDbType.Int16, 11, "itemCode");
cmd.Parameters.Add("?itemname", MySqlDbType.VarChar, 40, "poCode");
da2.InsertCommand = cmd;
//return da;
}
}