ImageVerifierCode 换一换
格式:DOCX , 页数:23 ,大小:19.83KB ,
资源ID:10286629      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10286629.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(集中整理ArcEngin在VB环境下开发时用到的资料.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

集中整理ArcEngin在VB环境下开发时用到的资料.docx

1、集中整理ArcEngin在VB环境下开发时用到的资料集中整理VB.NET操作ACCESS一,功能:1,对access数据库显示绑定(不同方式的显示)、添加、删除、更新、以及查询(不同方式的查询);2,建立新的access mdb文件,新建表,添加(删除)字段,及定义字段数据类型二,源代码如下:Imports System.Data.OleDbImports ADODBPublic Class sqlAccess#Region Private Private ConnectionStr As String = Private Conn As OleDb.OleDbConnection#End R

2、egion#Region sub new Sub New(ByVal AccessFileName As String) ConnectionStr = Provider = Microsoft.Jet.OLEDB.4.0;Data Source = & AccessFileName Conn = New OleDb.OleDbConnection(ConnectionStr) End Sub Sub New() End Sub#End Region#Region 显示数据 Public Sub ShowRecords(ByVal DG As DataGridView, ByVal Acces

3、TableName As String) Dim sqlString As String = SELECT * FROM & AccesTableName DG.ReadOnly = True Dim myDataSet As New DataSet() Using Conn Conn.Open() Dim myCommand As OleDbDataAdapter = New OleDbDataAdapter(sqlString, Conn) myCommand.Fill(myDataSet, AccesTableName) DG.DataSource = myDataSet.Tables(

4、0) Conn.Close() End Using End Sub Public Sub ShowRecords(ByVal DG As DataGridView, ByVal AccesTableName As String, ByVal cols As Collection) Dim sqlString As String = SELECT Dim i As Integer For i = 1 To cols.Count - 1 sqlString = sqlString & cols.Item(i) & , Next sqlString = sqlString & cols.Item(c

5、ols.Count) sqlString = sqlString & from & AccesTableName DG.ReadOnly = True Dim myConn As New OleDb.OleDbConnection(ConnectionStr) Dim myDataSet As New DataSet() Using myConn myConn.Open() Dim myCommand As OleDbDataAdapter = New OleDbDataAdapter(sqlString, myConn) myCommand.Fill(myDataSet, AccesTabl

6、eName) DG.DataSource = myDataSet.Tables(0) myConn.Close() End Using End Sub Public Function ShowRecords(ByVal AccessTableName As String) As DataTable Dim sqlString As String = SELECT * FROM & AccessTableName Dim myDataSet As New DataSet Using Conn Conn.Open() Dim myCommand As OleDbDataAdapter = New

7、OleDbDataAdapter(sqlString, Conn) myCommand.Fill(myDataSet, AccessTableName) Conn.Close() Return myDataSet.Tables(0) End Using End Function#End Region#Region 添加数据 Public Sub AddRecord(ByVal DG As DataGridView, ByVal AccesTableName As String, _ ByVal Cols As Collection, ByVal Vals As Collection) Dim

8、sqlString As String = insert into & AccesTableName & ( Dim i As Integer For i = 1 To Cols.Count - 1 sqlString = sqlString & Cols.Item(i).ToString & , Next sqlString = sqlString & Cols.Item(Cols.Count).ToString & ) values ( For i = 1 To Vals.Count - 1 sqlString = sqlString & ?, Next sqlString = sqlSt

9、ring & ?) 时间表达式2009-12-2 货币相当字符串如: 333 添加后显示 ¥333.00 ole对象,相当于二进制的数组 Dim myConn As New OleDb.OleDbConnection(ConnectionStr) Using myConn myConn.Open() Dim myCommand As OleDbCommand = New OleDbCommand(sqlString, myConn) For i = 1 To Vals.Count myCommand.Parameters.Add(New OleDb.OleDbParameter).Value

10、= Vals(i) Next myCommand.ExecuteNonQuery() myConn.Close() End Using 在dg中更新 ShowRecords(DG, AccesTableName) End Sub Public Sub AddRecord(ByVal AccesTableName As String, _ByVal Cols As Collection, ByVal Vals As Collection) Dim sqlString As String = insert into & AccesTableName & ( Dim i As Integer For

11、 i = 1 To Cols.Count - 1 sqlString = sqlString & Cols.Item(i).ToString & , Next sqlString = sqlString & Cols.Item(Cols.Count).ToString & ) values ( For i = 1 To Vals.Count - 1 sqlString = sqlString & ?, Next sqlString = sqlString & ?) 时间表达式2009-12-2 货币相当字符串如: 333 添加后显示 ¥333.00 ole对象,相当于二进制的数组 Using

12、Conn Conn.Open() Dim myCommand As OleDbCommand = New OleDbCommand(sqlString, Conn) For i = 1 To Vals.Count myCommand.Parameters.Add(New OleDb.OleDbParameter).Value = Vals(i) Next myCommand.ExecuteNonQuery() Conn.Close() End Using End Sub#End Region#Region 数据更新 Public Sub UpdateRecord(ByVal DG As Dat

13、aGridView, ByVal AccesTableName As String, _ByVal Cols As Collection, ByVal Vals As Collection, ByVal IndexColumnName As String, ByVal IndexValue As Object, ByVal isShowSqlString As Boolean) Dim sqlString As String = update & AccesTableName & set Dim i As Integer For i = 1 To Cols.Count - 1 If Vals.

14、Item(i).GetType.Name = String Then sqlString = sqlString & Cols.Item(i).ToString & = & Vals.Item(i) & , ElseIf Vals.Item(i).GetType.Name.Contains(Date) Then sqlString = sqlString & Cols.Item(i).ToString & = & Vals.Item(i) & , Else sqlString = sqlString & Cols.Item(i).ToString & = & Vals.Item(i) & ,

15、End If Next If Vals.Item(i).GetType.Name = String Then sqlString = sqlString & Cols.Item(Cols.Count).ToString & = & Vals.Item(Cols.Count) & ElseIf Vals.Item(i).GetType.Name.Contains(Date) Then sqlString = sqlString & Cols.Item(Cols.Count).ToString & = & Vals.Item(Cols.Count) & Else sqlString = sqlSt

16、ring & Cols.Item(Cols.Count).ToString & = & Vals.Item(Cols.Count) End If If IndexValue.GetType.Name = String Then sqlString = sqlString & where & IndexColumnName & = & IndexValue & Else sqlString = sqlString & where & IndexColumnName & = & IndexValue End If 目前只能实现更加数字,文本,是否来选取,时间等还没有实现,使用的时候要注意 If i

17、sShowSqlString Then MsgBox(sqlString) Using Conn Conn.Open() Dim cmd As OleDbCommand = New OleDbCommand(sqlString, Conn) cmd.ExecuteNonQuery() Conn.Close() End Using 在dg中更新 Dim dt As DataTable = DG.DataSource For Each r As DataRow In dt.Rows If r(IndexColumnName) = IndexValue Then For i = 1 To Cols.

18、Count r.Item(Cols(i) = Vals(i) Next End If Next End Sub Public Sub UpdateRecord(ByVal DG As DataGridView, ByVal AccesTableName As String, _ByVal Cols As Collection, ByVal Vals As Collection, ByVal isShowSqlString As Boolean) Dim sqlString As String = update & AccesTableName & set Dim i As Integer Fo

19、r i = 1 To Cols.Count - 1 If Vals.Item(i).GetType.Name = String Then sqlString = sqlString & Cols.Item(i).ToString & = & Vals.Item(i) & , ElseIf Vals.Item(i).GetType.Name.Contains(Date) Then sqlString = sqlString & Cols.Item(i).ToString & = & Vals.Item(i) & , Else sqlString = sqlString & Cols.Item(i

20、).ToString & = & Vals.Item(i) & , End If Next If Vals.Item(i).GetType.Name = String Then sqlString = sqlString & Cols.Item(Cols.Count).ToString & = & Vals.Item(Cols.Count) & ElseIf Vals.Item(i).GetType.Name.Contains(Date) Then sqlString = sqlString & Cols.Item(Cols.Count).ToString & = & Vals.Item(Co

21、ls.Count) & Else sqlString = sqlString & Cols.Item(Cols.Count).ToString & = & Vals.Item(Cols.Count) End If If isShowSqlString Then MsgBox(sqlString) 目前只能实现更加数字,文本,是否来选取,时间等还没有实现,使用的时候要注意 Using Conn Conn.Open() Dim cmd As OleDbCommand = New OleDbCommand(sqlString, Conn) cmd.ExecuteNonQuery() Conn.Clo

22、se() End Using Dim dt As DataTable = DG.DataSource For Each r As DataRow In dt.Rows Dim j As Integer For j = 1 To Cols.Count r.Item(Cols(i) = Vals(j) Next Next End Sub#End Region#Region 删除数据 Public Sub DeleteRecord(ByVal DG As DataGridView, ByVal AccesTableName As String, ByVal Id As Integer) Dim sq

23、lString As String = delete from & AccesTableName & where id= & Id Try Dim myConn As New OleDb.OleDbConnection(ConnectionStr) myConn.Open() Dim inst As OleDbCommand = New OleDbCommand(sqlString, myConn) inst.ExecuteNonQuery() myConn.Close() Catch ex As Exception MsgBox(ex.Message) End Try ShowRecords

24、(DG, AccesTableName) End Sub#End Region#Region 查找 开头是 Public Function SelectRecordsByString(ByVal AccesTableName As String, _ ByVal cols As Collection, ByVal vals As Collection) As DataTable Dim sqlString As String = SELECT * FROM & AccesTableName & where ( Dim i As Integer If vals.Count = 1 Then Re

25、turn Nothing For i = 1 To vals.Count - 1 sqlString = sqlString & cols(i) & = & vals.Item(i) & or Next sqlString = sqlString & cols(i) & = & vals.Item(vals.Count) & ) Dim myConn As New OleDb.OleDbConnection(ConnectionStr) Dim myDataSet As New DataSet() MsgBox(sqlString) Using myConn myConn.Open() Dim myCommand As OleDbDataAdapter = New OleDbDa

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1