473,396 Members | 2,154 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,396 software developers and data experts.

Adding row to data table in .net 2.0

DH
I have an untyped dataset with a table. I am trying to
programmatically add a row to this table. This was working in VS 2003
/ .net 1.1 I am receiving an error "Object reference not set to an
instance of an object."

Here is the code that worked in VS 2003 / .net 1.1:

row = dtLines.NewRow()
I tried the above code in VS 2005 / .net 2.0, and I also revised to
below, but I am still receiving the above error:

Dim row As DataRow = dsQuotes.Tables("dtLines").NewRow()

Why am I receiving this error?

Sep 8 '06 #1
1 1877
DH

I have been fiddling with adding rows and records
i think u might be looking for this..so if im wrong...i appologize for the
post.

I think you might be missing the fill command on the data table ?

Both codes work below... let me know if they help... and if they do, since i
dont know
the terminology, could ya let me know what you did wrong.
Would help me learn if I run into it as well.

Thanks

Miro
-Below is 2 pieces of code... 1 was given by newsgroup that got me started,
the other
is the "long" way of doing it without sql.
================code
Sub AddInitialRecords()
''''Add a quick Record thru SQL - given by Newsgroup...
''''Dim myConnectionString As String = _
''''"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
''''SystemFileDB & FileDBExtension
''''Dim myConnection As New OleDbConnection(myConnectionString)
''''myConnection.Open()
''''Dim myCommand As New OleDbCommand("INSERT INTO DBVersion
(CurVersion) VALUES (?)", _
'''' myConnection)
''''myCommand.Parameters.Add("Param1", OleDbType.VarChar, 50).Value
= "2.00"
''''myCommand.ExecuteNonQuery()
''''myCommand.Dispose()
''''myConnection.Close()

'Add a record the long way thru normal statements.
Dim cnADONetConnection As New OleDb.OleDbConnection()
Dim myConnectionString As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
SystemFileDB & FileDBExtension
cnADONetConnection.ConnectionString = myConnectionString

cnADONetConnection.Open()

Dim daDataAdapter As New OleDb.OleDbDataAdapter()
daDataAdapter = _
New OleDb.OleDbDataAdapter("Select * From DBVersion",
cnADONetConnection)
Dim cbCommandBuilder As OleDb.OleDbCommandBuilder

cbCommandBuilder = New OleDb.OleDbCommandBuilder(daDataAdapter)

Dim dtVersion As New DataTable()
Dim dtRowPosition As Integer = 0 ' i dont think i use this anywhere
but later i will
'Fill with data
daDataAdapter.Fill(dtVersion)

Dim NoOfRecs As Integer = 0
'Go to first row
Dim rwVersion As DataRow '= dtVersion.Rows(0)
NoOfRecs = dtVersion.Rows.Count()

If NoOfRecs = 0 Then
MsgBox("no recs")
rwVersion = dtVersion.NewRow()

rwVersion("CurVersion") = "3.33"

dtVersion.Rows.Add(rwVersion)
daDataAdapter.Update(dtVersion)

Debug.WriteLine("added record - " +
dtVersion.Rows(dtVersion.Rows.Count - 1)("CurVersion").ToString)

Else
MsgBox("there are recs")
rwVersion = dtVersion.Rows(0)
Debug.WriteLine("read record - " + _
rwVersion("CurVersion").GetType.ToString)
End If

'Dim blastring As String = dtVersion.Rows(0)("CurVersion").ToString

Debug.WriteLine("Done debuging")

cnADONetConnection.Close()

End Sub
================end of code




"DH" <dc********@yahoo.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
>I have an untyped dataset with a table. I am trying to
programmatically add a row to this table. This was working in VS 2003
/ .net 1.1 I am receiving an error "Object reference not set to an
instance of an object."

Here is the code that worked in VS 2003 / .net 1.1:

row = dtLines.NewRow()
I tried the above code in VS 2005 / .net 2.0, and I also revised to
below, but I am still receiving the above error:

Dim row As DataRow = dsQuotes.Tables("dtLines").NewRow()

Why am I receiving this error?

Sep 14 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Paul | last post by:
Hi I have a table that currently has 466 columns and about 700,000 records. Adding a new DEFAULT column to this table takes a long time. It it a lot faster to recreate the table with the new...
2
by: Chris Cobb | last post by:
I have a table that currently contains 718000 rows. I wish to add a column to the table. Adding this column anywhere other than the end of the table requires exporting data, a drop and recreate,...
3
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding 2-3 new columns worth. Now my questions are:...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
3
by: Tyler Carver | last post by:
I am trying to use some dynamic controls that are built and then added to tables. The problem that I am having is the timing of when I can populate the controls and have the state remain after a...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
10
by: Trevor | last post by:
Hey, I am trying to do this tutorial on the microsoft site : http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dndotnet/html/usingadonet.asp I can get everything to work up to...
2
by: Steve | last post by:
I have zero experience with ODBC. If I have an Access frontend connected to a SQL Database using ODBC, are the tables connected like a frontend/backend Access database where the the tables you see...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.