我在vb.net 中新建了一个dataset,通过编程生成数据,填充到dataset中,然后通过datagrid显示出来,现在我要把datagrid中的数据表保存到一个access数据库文件中,应怎样实现?请帮帮忙!急等!!!
我用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