By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Please help, about primary key and dataset

P: n/a
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
Nov 17 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi,

Are you sure there is a column named Number?

Ken
------------------------
"Warex" <Ig************@juno.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
>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


Nov 17 '06 #2

P: n/a
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.....
"Ken Tucker [MVP]" <vb***@bellsouth.netwrote in message
news:uI***************@TK2MSFTNGP04.phx.gbl...
Hi,

Are you sure there is a column named Number?

Ken
------------------------
"Warex" <Ig************@juno.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
>>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



Nov 17 '06 #3

P: n/a
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

"Warex" <Ig************@juno.comschreef in bericht
news:Ow**************@TK2MSFTNGP04.phx.gbl...
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.....
"Ken Tucker [MVP]" <vb***@bellsouth.netwrote in message
news:uI***************@TK2MSFTNGP04.phx.gbl...
>Hi,

Are you sure there is a column named Number?

Ken
------------------------
"Warex" <Ig************@juno.comwrote in message
news:u7**************@TK2MSFTNGP03.phx.gbl...
>>>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




Nov 17 '06 #4

P: n/a
Warex wrote:
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.
Nov 17 '06 #5

P: n/a
Thanks, I found the problem to your help,
Simply was a table declaration that was wrong while passing through
functions.
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:ej**********@south.jnrs.ja.net...
Warex wrote:
>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.

Nov 17 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.