结构:
myshow()用来统一显示; 对单独的模块,例如radiobox,combox要单独处理,之后分别做增删改浏览的按钮响应事件;
// myshow
public void MyShow()
{
string sql = @"SELECT [TNo]
,[TNmae]
,[TSex]
FROM [test2013].[dbo].[TEACHERS]";
dv.DataSource = DBHelperSQL.TableSelect(sql);
}
//细分的四个功能模块
(1)在编程时,四个模块要单独写,就是要分别在sql server复制到剪切板上sql语句,粘贴在代码中,划线部分
(2)点击事件,要一个一个加,切勿直接copy,出很多麻烦
private void btnAdd_Click(object sender, EventArgs e)
{
string sql = @"INSERT INTO [test2013].[dbo].[TEACHERS]
([TNo]
,[TNmae]
,[TSex])
VALUES(@TNo,@TNmae,@TSex)";
SqlParameter[] para = { new SqlParameter("@TNo", txtTNo.Text),
new SqlParameter("@TNmae", txtTName.Text),
new SqlParameter("@TSex",sex )};
DBHelperSQL.TableChange(sql,para);
MyShow();
}
private void btnDelete_Click(object sender, EventArgs e)
{
string sql = @"DELETE FROM [test2013].[dbo].[TEACHERS]
WHERE [TNo] =@TNo";
SqlParameter[] para = { new SqlParameter("@TNo", txtTNo.Text)};
DBHelperSQL.TableChange(sql, para);
MyShow();
}
private void btnSelect_Click(object sender, EventArgs e)
{
string sql = @"SELECT [TNo]
,[TNmae]
,[TSex]
FROM [test2013].[dbo].[TEACHERS]
WHERE [TNo] =@TNo or [TNmae] =@TNmae or [TSex] = @TSex";
SqlParameter[] para = { new SqlParameter("@TNo", txtTNo.Text),
new SqlParameter("@TNmae", txtTName.Text),
new SqlParameter("@TSex",sex )};
dv.DataSource = DBHelperSQL.TableSelect(sql, para);
}
private void btnUpdate_Click(object sender, EventArgs e)
{
string sql = @"UPDATE [test2013].[dbo].[TEACHERS]
SET [TNmae] =@TNmae
,[TSex] = @TSex
WHERE [TNo] =@TNo";
SqlParameter[] para = { new SqlParameter("@TNo", txtTNo.Text),
new SqlParameter("@TNmae", txtTName.Text),
new SqlParameter("@TSex",sex )};
DBHelperSQL.TableChange(sql, para);
MyShow();
}