Home All Groups Group Topic Archive Search About

Please help, about primary key and dataset

Author
17 Nov 2006 12:20 AM
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

Author
17 Nov 2006 1:18 AM
Ken Tucker [MVP]
Hi,

        Are you sure there is a column named Number?

Ken
------------------------
Show quoteHide quote
"Warex" <Igiveitalla***@juno.com> wrote in message
news:u7Teq4dCHHA.4372@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
>
>
Author
17 Nov 2006 5:29 AM
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.....
Show quoteHide quote
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uIa%23EZeCHHA.204@TK2MSFTNGP04.phx.gbl...
> Hi,
>
>        Are you sure there is a column named Number?
>
> Ken
> ------------------------
> "Warex" <Igiveitalla***@juno.com> wrote in message
> news:u7Teq4dCHHA.4372@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
>>
>>
>
>
Author
17 Nov 2006 5:58 AM
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

Show quoteHide quote
"Warex" <Igiveitalla***@juno.com> schreef in bericht
news:OwZfVlgCHHA.3476@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.net> wrote in message
> news:uIa%23EZeCHHA.204@TK2MSFTNGP04.phx.gbl...
>> Hi,
>>
>>        Are you sure there is a column named Number?
>>
>> Ken
>> ------------------------
>> "Warex" <Igiveitalla***@juno.com> wrote in message
>> news:u7Teq4dCHHA.4372@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
>>>
>>>
>>
>>
>
>
Author
17 Nov 2006 12:51 PM
Phill W.
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.
Author
17 Nov 2006 11:03 PM
Warex
Thanks, I found the problem to your help,
Simply was a table declaration that was wrong while passing  through
functions.
Show quoteHide quote
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> wrote in message
news:ejkb8u$3ka$1@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.