spaced Posted September 17, 2003 Posted September 17, 2003 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 Quote
Administrators PlausiblyDamp Posted September 17, 2003 Administrators Posted September 17, 2003 (edited) Are dsContacts and dsContacts.ContactList set to valid instances? Edited March 22, 2007 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
spaced Posted September 17, 2003 Author Posted September 17, 2003 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. Quote
Administrators PlausiblyDamp Posted September 18, 2003 Administrators Posted September 18, 2003 If you are using the Cache object the objects may have expired. You may need to check if they are valid before using them. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
elikakohen Posted September 18, 2003 Posted September 18, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.