使用向导连接ASSECC数据库时connection ,dataadapter ,dataview,dataset,currencymanager怎么表示的?怎
使用向导连接ASSECC数据库时connection ,dataadapter ,dataview,dataset,currencymanager怎么表示的?怎么调用?
Imports System.Data Imports System.Data.OleDb Module Moddata Dim constr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\172.31.199.28\public\共享文档\data\考勤注册码.mdb" Dim conn As OleDbConnection #Region "填充返回dataset" Public Function mydataset(ByVal sqlstr As String) As DataSet Try conn = New OleDbConnection(constr) conn.Open() Dim da As OleDbDataAdapter = New OleDbDataAdapter(sqlstr, conn) Dim ds As DataSet = New DataSet da.Fill(ds) Return ds Catch ex As Exception MsgBox(ex.Message.ToString, MsgBoxStyle.Information, "提示") Finally conn.Close() End Try End Function #End Region #Region "执行SQL语句" Public Sub exesqlcommand(ByVal sqlstr As String) Try conn = New OleDbConnection(constr) conn.Open() Dim sqlcmd As OleDbCommand sqlcmd = New OleDbCommand(sqlstr, conn) sqlcmd.ExecuteNonQuery() Catch ex As Exception MsgBox(ex.Message.ToString, MsgBoxStyle.Information, "提示") Finally conn.Close() End Try End Sub #End Region #Region "执行统计" Public Function exesqlscalar(ByVal sqlstr As String) As Integer Try conn = New OleDbConnection(constr) conn.Open() Dim sqlsc As OleDbCommand Dim sqlcount As Integer sqlsc = New OleDbCommand(sqlstr, conn) sqlcount = sqlsc.ExecuteNonQuery() exesqlscalar = sqlcount Catch ex As Exception MsgBox(ex.Message.ToString, MsgBoxStyle.Information, "提示") Finally conn.Close() End Try End Function #End Region #Region "数据读取返回单一字段值" Public Function exesqlreader(ByVal sqlstr As String) As String Try Dim myread As OleDbDataReader conn = New OleDbConnection(constr) conn.Open() Dim sqlcmd As OleDbCommand sqlcmd = New OleDbCommand(sqlstr, conn) myread = sqlcmd.ExecuteReader myread.Read() exesqlreader = myread.Item(0) Catch ex As Exception MsgBox(ex.Message.ToString, MsgBoxStyle.Information, "提示") Finally conn.Close() End Try End Function #End Region End Module最普遍的数据库连接方法 。只需改下数据库地址就行。。使用的时候,直接调用
Dim mytable As DataTable = mydataset("select * from data where 店铺名称= '" & idflag & "'").Tables(0) Me.Tname.Text = idflag Tnum.Text = mytable.Rows(0).Item(0).ToString Tkjh.Text = mytable.Rows(0).Item(2).ToString Ttel.Text = mytable.Rows(0).Item(3).ToString Tqqm.Text = mytable.Rows(0).Item(4).ToString Tzcm.Text = mytable.Rows(0).Item(5).ToString Call exesqlcommand("insert into data(店铺名称,联系电话,卡机号,软件请求码,注册码)values ('" & name1 & "','" & tel & "','" & kjh & "','" & qqm & "', '" & zcm & "')") MsgBox("增加成功", MsgBoxStyle.Information, "提示") Call exesqlcommand("update data set 店铺名称='" & name1 & "',联系电话='" & tel & "',卡机号='" & kjh & "', 软件请求码='" & qqm & "',注册码='" & zcm & "' where ID =" & num) MsgBox("更新成功 ", MsgBoxStyle.Information, "提示")