datagridview 数据处理方法 修改 删除 添加 下拉类表 弹出窗口
//cmb_Temp.DropDownStyle =ComboBoxStyle.DropDown; //可以写入 // cmb_Temp.DropDownStyle = ComboBoxStyle.Simple;
}
private void button1_Click(object sender, EventArgs e)
{
//提交数据库操作,。。。。。修改数据
DataOperate mydopt = new DataOperate();
string mysql = "";
//修改数据
if(ID_TB.Text!="-1")
mysql = "update user_tb1 set user_id='" + USER_ID_TB.Text
+ "',user_password='" + USER_PWD_TB.Text
+ "',user_class_id=" + USER_CLASS_CB.SelectedValue
+ ",user_name='" + USER_NAME_TB.Text
+ "',user_sex='" + USER_SEX_TB.Text
+ "' where id=" +ID_TB.Text;
else if (ID_TB.Text == "-1")
{ mysql = "insert into user_tb1
(user_id,user_password,user_class_id,user_name,user_sex) values('"
+ USER_ID_TB.Text + "','"
+ USER_PWD_TB.Text + "',"
+ USER_CLASS_CB.SelectedValue + ",'"
+ USER_NAME_TB.Text + "','"
+ USER_SEX_TB.Text + "')";
}
// MessageBox.Show(mysql);
mydopt.getCom(mysql);
this.DialogResult = DialogResult.OK;
}
private void button2_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
}
}
三、 直接在datagridview上修改、添加、删除。不需要添加textbox。而且在view