代码~~~~
类
Imports System.Data.OleDb
Module Commonmodule
Public mydap As OleDbDataAdapter
'建立DataSet对象
Public mydataset As DataSet = New DataSet
'定义一个表对象
Public mytable As DataTable
'定义一个行对象
Public myrow As DataRow
'定义一个OleDbCommandBuilder对象,用于协调DataSet的更改所自动生成的单表命令
Public mycmdbuildder As OleDbCommandBuilder
Public Function SQLOpera(ByVal str As String, ByVal table As String) 'str参数为查询语句,table为所要执行的表
Try
'定义一个存储当前行数的变量
Dim row As Integer = 0
'定义一个执行SQL命令的字符串变量
Dim Selectstring As String
Selectstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
'使用相对路径
Selectstring = Selectstring & Application.StartupPath() & "\Data\mydb.mdb"
mydap = New OleDbDataAdapter(str, Selectstring)
'清除数据集的所有表
mydataset.Clear()
mydataset.Tables.Clear()
'填充数据集
mydap.Fill(mydataset, table)
'获取数据集中的表
mytable = mydataset.Tables.Item(0)
myrow = mytable.Rows.Item(row)
Catch ex As Exception
End Try
Return Nothing
End Function
End Module
user窗体
Public Class user
Private Sub ShowCurrentPosition()
Me.TextBox3.Text = Me.BindingContext(Commonmodule.mydataset, "管理员表").Position + 1 & " of " & Me.BindingContext(Commonmodule.mydataset, "管理员表").Count
'显示当前数据绑定的管理对象的数据位置
End Sub
Private Sub bangding()
Dim tablename As String = "管理员表"
Dim strr As String
strr = "select 用户,密码,身份,前台营业,外卖服务,酒宴预定,员工管理 from 管理员表"
Commonmodule.SQLOpera(strr, tablename)
Try
Me.TextBox1.DataBindings.Clear()
Me.TextBox2.DataBindings.Clear()
()
Me.CheckBox1.DataBindings.Clear()
Me.CheckBox2.DataBindings.Clear()
Me.CheckBox3.DataBindings.Clear()
Me.CheckBox4.DataBindings.Clear()
Me.TextBox1.DataBindings.Add("text", Commonmodule.mydataset, "管理员表.用户")
Me.TextBox2.DataBindings.Add("text", Commonmodule.mydataset, "管理员表.密码")
("text", Commonmodule.mydataset, "管理员表.身份")
Me.CheckBox1.DataBindings.Add("Checked", Commonmodule.mydataset, "管理员表.前台营业")
Me.CheckBox2.DataBindings.Add("Checked", Commonmodule.mydataset, "管理员表.外卖服务")
Me.CheckBox3.DataBindings.Add("Checked", Commonmodule.mydataset, "管理员表.酒宴预定")
Me.CheckBox4.DataBindings.Add("Checked", Commonmodule.mydataset, "管理员表.员工管理")
ShowCurrentPosition()
Catch ex As Exception
MsgBox("该学号的注册信息不存在!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Information...")
End Try
End Sub
Private Sub QXbangding()
Me.TextBox1.DataBindings.Clear()
Me.TextBox2.DataBindings.Clear()
()
Me.CheckBox1.DataBindings.Clear()
Me.CheckBox2.DataBindings.Clear()
Me.CheckBox3.DataBindings.Clear()
Me.CheckBox4.DataBindings.Clear()
End Sub
Private Sub user_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
bangding()
End Sub
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Me.BindingContext(Commonmodule.mydataset, "管理员表").Position += 1
ShowCurrentPosition()
End Sub
Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
Me.BindingContext(Commonmodule.mydataset, "管理员表").Position -= 1
ShowCurrentPosition()
End Sub
Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
Me.BindingContext(Commonmodule.mydataset, "管理员表").Position = 0
ShowCurrentPosition()
End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
Me.BindingContext(Commonmodule.mydataset, "管理员表").Position = Me.BindingContext(Commonmodule.mydataset, "管理员表").Count - 1
ShowCurrentPosition()
End Sub
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
QXbangding()
TextBox1.Text = ""
TextBox2.Text = ""
ComboBox1.Text = "超级管理员"
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
btnDelete.Enabled = False
btnSearch.Enabled = False
btnAdd.Enabled = True
'
GroupBox3.Enabled = False
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
Dim tablename As String = "管理员表"
Dim strr As String
strr = "select * from 管理员表"
Try
'传递参数,执行公共模块的SQLOpera函数
Commonmodule.SQLOpera(strr, tablename)
'建立一个新的行对象,以便在数据集中插入新行
Dim addrow As DataRow = Commonmodule.mytable.NewRow
'将信息添加进新行中
addrow.Item(0) = Trim(TextBox1.Text)
addrow.Item(1) = Trim(TextBox2.Text)
addrow.Item(2) = Trim(ComboBox1.Text)
addrow.Item(3) = CheckBox1.Checked
addrow.Item(4) = CheckBox2.Checked
addrow.Item(5) = CheckBox3.Checked
addrow.Item(6) = CheckBox4.Checked
'将新行添加进表中
mytable.Rows.Add(addrow)
'使用OleDbCommandBuilder对象自动生成SQL命令
Commonmodule.mycmdbuildder = New OleDb.OleDbCommandBuilder(Commonmodule.mydap)
'更新数据库
Commonmodule.mydap.Update(Commonmodule.mydataset, tablename)
'使用对话框提示用户添加成功
MsgBox("添加成功!", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Information...")
btnDelete.Enabled = True
btnSearch.Enabled = True
btnAdd.Enabled = False
'GroupBox3.Enabled = True
Dim tablenamea As String = "员工管理"
Dim strra As String
strra = "select 员工编码,真实姓名,性别 from 员工管理"
Commonmodule.SQLOpera(strra, tablenamea)
Me.TextBox1.DataBindings.Clear()
Me.TextBox2.DataBindings.Clear()
()
Me.CheckBox1.DataBindings.Clear()
Me.CheckBox2.DataBindings.Clear()
Me.CheckBox3.DataBindings.Clear()
Me.CheckBox4.DataBindings.Clear()
Me.TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("text", Commonmodule.mydataset, "员工管理.员工编码"))
Me.TextBox2.DataBindings.Add(New System.Windows.Forms.Binding("text", Commonmodule.mydataset, "员工管理.真实姓名"))
(New System.Windows.Forms.Binding("text", Commonmodule.mydataset, "员工管理.性别"))
'
Me.CheckBox1.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Commonmodule.mydataset, "管理员表.前台营业"))
'
Me.CheckBox2.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Commonmodule.mydataset, "管理员表.外卖服务"))
'
Me.CheckBox3.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Commonmodule.mydataset, "管理员表.酒宴预定"))
'
Me.CheckBox4.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Commonmodule.mydataset, "管理员表.员工管理"))
ShowCurrentPosition()
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Information...")
End Try
End Sub
End Class