473,385 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Please help, about primary key and dataset

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
5 1351
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: EMW | last post by:
Hi, Could you please take a look and tell me what this means? Cor has tried to help me, but we haven't found it yet. Everytime I run this code, I get an exception error. Here is my code: ...
2
by: Neeper | last post by:
I'm writing an application that displays a list of transactions from a mysql database. The problem I am having is I need the user to be able to view the last x transactions but there needs to be an...
0
by: news.microsoft.com | last post by:
first i apologize for the potential crosspost. this group gets far more traffic. now that i have that out of the way... ;) apparently using AutoGenerated Commands on Command objects does not work...
4
by: steroche | last post by:
I would REALLY appreciate help please please please! Im sure it is probably blindingly obvious to most of you but I am totally in the dark here!I am lost - i thought i had finally figured out this...
10
by: Bernie Yaeger | last post by:
I have a need to add a primary key to a dataset/datatable. How can this be done using a standard oledb data provider? Tx for any help.
9
by: Steven C. | last post by:
Hello: I'm getting an error, "primary key not defined" when trying to use the FIND method on the DataTable Rows collection. I have a typed dataset called 'MortgagesDS' that I created with the...
1
by: GS | last post by:
set primary key option is greyed out in the dataset designer for a table Details In an vb.net express 2005 project, I have a dataset associated with table. lets call this table codetable. the...
3
by: iKiLL | last post by:
Hi all The Code is below but i will give you a brief over view first. I am using C#, SQL Mobile and the CF2.0 with Merge Replication. My Primary Keys are all "uniqueidentifier" types...
1
by: Rainer Queck | last post by:
Hello NG, I am using a typed DataSet, created with VS dataset designer. I have the problem , that a table in the dataset refuses to read a xml file. The strange thing is that if I create a...
0
by: nzkks | last post by:
Hi, I am trying the following SQL to fetch the needed data. The query works in query analyzer in SQL Server 2005. But in data adapter in a dataset in Visual Studio 2005, I am getting the data with...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.