|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Please help, about primary key and datasetgiving 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 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 > > 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 >> >> > > 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 >>> >>> >> >> > > Warex wrote:
> I am using the example from the microscuzz site on making a key but It keeps The Immediate Window is your friend.> 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. 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. 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.
rewriting URL
appsetting in class doesn't work RaiseEvent xml file format Speeding up array/file loading Export function from VB.Net DLL vb 2005 standard question Dynamically iterating through log files passing parameter to class from application my class library doesn't contain an assembly - how to add an assem |
|||||||||||||||||||||||