mysql数据库的增删改查
try
{
//将新用户信息插入数据库
string strsql = "insert into httang_test.test(id,name,password,adress) values('" + this.IdTextBox.Text + "','" + this.NameTextBox.Text + "','" + this.PassWordTextBox.Text + "','" + this.AdressTextBox.Text + "');";
DataTable dt = MySqlHelper.QueryDataTable(strsql);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
//成功提示,跳转
MessageBox.Show("新用户添加成功!");
information infor = new information();
infor.ShowDialog();
--------------------------------------------------------------------------------------------------------------------------------------------
//定义管理员帐户密码
string user = "whx";
int pass = 1111;
//条件判断
if (user == this.UserTextBox.Text && pass == Convert.ToInt32(this.PassTextBox.Text))
{
//符合条件,跳转新用户添加
register re = new register();
re.ShowDialog();
}
else {
//错误提示
MessageBox.Show("请输入正确的管理员帐号");
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------
//用户信息查询
try
{
//查询所有信息列表
string strSql = "select * from httang_test.test ";
DataTable dt = MySqlHelper.QueryDataTable(strSql);
dataGridView1.DataSource = dt;
dataGridView1.AutoResizeColumns();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
---------------------------------------------------------------------------------------------------------------------------------------------------------------
//用户信息修改
try
{
//根据输入信息,更新用户信息
string strsql = "update httang_test.test set id='" + this.textBox1.Text + "', name='" + this.textBox2.Text + "', password='" + this.textBox3.Text + "', adress='" + this.textBox4.Text + "' where id='" + this.textBox1.Text + "';";
DataTable dt = MySqlHelper.QueryDataTable(strsql);
dataGridView1.DataSource = dt;
dataGridView1.AutoResizeColumns();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//用户信息删除
try
{
//根据输入的ID,删除该行用户信息
string strsql = "delete from httang_test.test where id ='" + this.deletebox.Text + "';";
DataTable dt = MySqlHelper.QueryDataTable(strsql);
dataGridView1.DataSource = dt;
dataGridView1.AutoResizeColumns();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}