标题:[原创]怎样把datagrid中的数据导出为access数据库文件?
只看楼主
rengh
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-3-3
 问题点数:0 回复次数:2 
[原创]怎样把datagrid中的数据导出为access数据库文件?
各位高手帮帮忙,怎样把datagrid中的数据导出为access数据库文件?
我在vb.net 中新建了一个dataset,通过编程生成数据,填充到dataset中,然后通过datagrid显示出来,现在我要把datagrid中的数据表保存到一个access数据库文件中,应怎样实现?请帮帮忙!急等!!!
搜索更多相关主题的帖子: 数据库 datagrid access 文件 
2006-01-27 12:07
rengh
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-3-3
得分:0 
斑竹,帮帮忙!

2006-02-02 23:17
rengh
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-3-3
得分:0 

我用adox保存建立一个类,创建access文件,代码如下:总是提示"参数类型错误"是怎么回事?
Imports ADOX
Public Class Class1
Public Function CreateAccessDB(ByVal NewDBPathName As String, ByVal paswd As String, ByRef addtable As DataTable) As Integer
Dim i As Integer = 1
Dim cat As Catalog = New Catalog
Try
cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & NewDBPathName & ";Jet OLEDB:Database Password=" & paswd & ";")
cat=nothing
Catch
i = 0
MsgBox("错误号 : " & Err.Number.ToString & " 错误描述:" & Err.Description.ToString)
End Try
cat = Nothing
Return i
End Function
Public Sub createtable(ByVal dbname As String, ByVal paswd As String, ByRef addtable As DataTable)
Try
Dim i As Integer
i = addtable.Columns.Count
Dim xx(i) As String
Dim x As Integer
Dim xxx(i) As ADOX.DataTypeEnum
For x = 0 To i - 1
xx(x) = addtable.Columns(x).ColumnName.ToString
Select Case addtable.Columns(x).DataType.ToString
Case "System.Int32"
xxx(x) = DataTypeEnum.adInteger
Case "System.String"
xxx(x) = DataTypeEnum.adBSTR
Case "System.Boolean"
xxx(x) = DataTypeEnum.adBoolean
Case "System.Byte"
xxx(x) = DataTypeEnum.adBinary
Case " System.Char"
xxx(x) = DataTypeEnum.adChar
Case " System.DateTime"
xxx(x) = DataTypeEnum.adDate
Case "System.Double"
xxx(x) = DataTypeEnum.adDouble
Case "System.Int16"
xxx(x) = DataTypeEnum.adSmallInt
Case " System.Int64"
xxx(x) = DataTypeEnum.adBigInt
Case " System.Single"
xxx(x) = DataTypeEnum.adSingle
End Select
Next x
Dim cat2 As New ADOX.Catalog
cat2.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & dbname & ";Password=" & paswd & ";"
Dim tbl As New Table
tbl.Name = addtable.TableName.ToString
Dim k As Integer
For k = 0 To i - 1
tbl.Columns.Append(xx(k), xxx(k))
Next k
cat2.Tables.Append(tbl)
cat2 = Nothing
Catch ex As Exception
MsgBox(ex.Message)
End Try

End Sub


2006-02-02 23:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-44084-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.065222 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved