W
Warex
I am using the example from the microscuzz site on making a key but It keeps
giving me an error:
With DataSets.Tables("Numbers")
.PrimaryKey = New DataColumn() {.Columns("Number")}
End With
Error:
Object reference not set to an instance of an object.
New is there, what is it talking about? Below is my code.
My wall has a hole now........
Thanks
Public Function GetAdapterandDataset(ByRef con As OleDb.OleDbConnection,
ByRef Msql As String, ByRef InsertDeleteUpdate As String)
Dim DAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(Msql,
con)
Dim CBuild As New OleDb.OleDbCommandBuilder
Dim DataSets As New DataSet
DAdapter.Fill(DataSets, "Tables")
'create pkey
With DataSets.Tables("Numbers")
..PrimaryKey = New DataColumn() {.Columns("Number")}
End With
'set command
Select Case InsertDeleteUpdate
Case "Insert"
DAdapter.InsertCommand = CBuild.GetInsertCommand()
Case "Update"
DAdapter.InsertCommand = CBuild.GetUpdateCommand()
Case "Delete"
DAdapter.InsertCommand = CBuild.GetDeleteCommand()
End Select
'use the Dataadapter.update (Dataset,"Table")
'use the ds.acceptchanges to
Dim returnit As New Returnit
returnit.DA = DAdapter
returnit.DS = DataSets
Return returnit
End Function
giving me an error:
With DataSets.Tables("Numbers")
.PrimaryKey = New DataColumn() {.Columns("Number")}
End With
Error:
Object reference not set to an instance of an object.
New is there, what is it talking about? Below is my code.
My wall has a hole now........
Thanks
Public Function GetAdapterandDataset(ByRef con As OleDb.OleDbConnection,
ByRef Msql As String, ByRef InsertDeleteUpdate As String)
Dim DAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(Msql,
con)
Dim CBuild As New OleDb.OleDbCommandBuilder
Dim DataSets As New DataSet
DAdapter.Fill(DataSets, "Tables")
'create pkey
With DataSets.Tables("Numbers")
..PrimaryKey = New DataColumn() {.Columns("Number")}
End With
'set command
Select Case InsertDeleteUpdate
Case "Insert"
DAdapter.InsertCommand = CBuild.GetInsertCommand()
Case "Update"
DAdapter.InsertCommand = CBuild.GetUpdateCommand()
Case "Delete"
DAdapter.InsertCommand = CBuild.GetDeleteCommand()
End Select
'use the Dataadapter.update (Dataset,"Table")
'use the ds.acceptchanges to
Dim returnit As New Returnit
returnit.DA = DAdapter
returnit.DS = DataSets
Return returnit
End Function