Please help, about primary key and dataset

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
 
W

Warex

Yes, my table name is "Numbers" and the field name of the first column is
"Number"

but I will look at it again......

out of curiosity why did microscam change data? recordsets worked fine for
me.....
 
C

Cor Ligthert [MVP]

Warex,

Are you using your recordset as well on a mobile device or as a disconnected
set on the Network.

However, you can still use your recordset, with all problems that are with
it.
If you did not have those, nobody is telling you that you may not use
recordset the pain now or in future is still for you.

Cor
 
P

Phill W.

Warex said:
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.

The Immediate Window is your friend.

Stick a break point on the above line and use the Immediate Window to
find out which of the objects is set to Nothing.

OK, you have to fully qualify each variable (you can't use access
..PrimaryKey directly any more) but you can still get there, with a bit
of digging.

Regards,
Phill W.
 
W

Warex

Thanks, I found the problem to your help,
Simply was a table declaration that was wrong while passing through
functions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top