Jump to content
Xtreme .Net Talk

Object reference not set to an instance of an object.


Recommended Posts

Posted

Line 220: ' Create a new row object for the Contacts table

Line 221: Dim rNew As DataSet1.ContactListRow

Line 222: rNew = dsContacts.ContactList.NewContactListRow

Line 223: ' Add data to the row

Line 224: rNew.ContactID = GetNewID(dsContacts.Tables("ContactList"))

 

I'm attempting to add a new row of data (contact information) into a dataset (and then into a sql server table itself). But I get a line error on 222 stating that the object reference isn't set to an instance of an object. It seems like it was declared in the line above, but isn't working for some reason.

 

Any suggestions?

 

Thanks in advance,

spaced

Posted

Dim adptContactList As SqlDataAdapter

Dim dsContacts As DataSet1

Public dsDepartment As DataSet2

 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

dsContacts = Cache("DataSet1")

dsDepartment = Cache("DataSet2")

adptContactList = Cache("adptContactList")

If Not IsPostBack Then

SqlDataAdapter1.Fill(DepartmentNames)

txtDept.DataBind()

End If

End Sub

 

I'm not sure if this is what you're looking for as I'm somewhat new to this stuff. Oh, and I'm basing this code off of material covered in the MCAD/MCSD Self-Paced Training Kit series for Developing Web Applications with VB.NET and C#.NET.

Posted

spaced,

 

This is C# but I hope it helps...

 

 

BookDataSet newBookDataSet;

newBookDataSet = new BookDataSet();

 

 

// This is the line I think you are missing

BookDataSet.BookRow newBookRow = newBookDataSet.Book.NewBookRow();

 

newBookRow.ID = DateTime.Now.Ticks.ToString();

newBookRow.Name = BookName.Text.Trim();

newBookRow.Summary = BookSummary.Text.Trim();

 

newBookDataSet.Book.AddBookRow(newBookRow);

 

 

Hope this helps.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...