Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 30th, 2005, 12:02 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default Help adding a row to a data table.

To make the explination short, what I have is a listbox bound to a dataset. I want to add a custom row to the dataset so that it is on top of the listbox. This is my code, however I keep getting an error: "Object Reference not set to an instance of an object"

            Dim dr As dsSites.SitesRow '<-- My dataset row
            dr.SiteID = 0 '<--The error occurs here
            dr.Site = "DUMMY"
            dr.Address1 = "DUMMY" '
            dr.Address2 = "DUMMY" '
            dr.City = "DUMMY"
            dr.State = "DUMMY"
            dr.Zip = "99999" ''
            dr.Phone = "9999999999"
            DsSites1.Tables(0).Rows.InsertAt(dr, 0) '<--Should put the row on top of the dataset.

Any help would be appreciated.

Jim
 
Old March 30th, 2005, 12:22 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Ok everyone, I fixed that problem but now have a new one.

The row gets inserted but always shows up on the bottom of my listbox, even when I use InsertAt(dr, 0).

Any Help?
Thanks

 
Old March 30th, 2005, 02:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I am currently working on an application with almost the same code except that I am not binding my data and mine is inserting it in the correct spot.

Are you sure that it isn't inserting correctly in your dataset table and then just placing it in the wrong place in the listbox? I am not sure if since it is bound it will just automatically add that value to the bottom of the listbox even though you insert it at a different spot.

After inserting it in the dataset, can you loop through the dataset and output it to the debugger window to see the order?

J
 
Old March 30th, 2005, 02:12 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Thanks for the reply. Acutally what I have is a DataView tied to the dataset table. I use it for filtering. What I did was, place a sort on the dataview, after the dataset was filled. This cured my problem.


   I am not sure, but I think it has something to do with binding order. It as if it inserts the row after binding, but then you have to reorder. I am not sure.





Similar Threads
Thread Thread Starter Forum Replies Last Post
URGENT adding new data in new row mingfatty Access 1 February 8th, 2007 08:24 AM
Adding new row ShaileshShinde Access VBA 23 July 5th, 2006 08:26 AM
UPDATING 1 row with another row in same table rit01 SQL Server 2000 3 February 19th, 2006 08:55 AM
Manage data row by row in datagrid Dragonist Classic ASP Databases 5 July 29th, 2004 04:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.