try { //將新用戶信息插入資料庫 string strsql = "insert into httang_test.test(id,name,password,adress) values('" + this.IdTextBox.Text + "','" + this.NameTextBox. ...
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);
}