Adding new rows to the existing dataset table in

Posted on 2012-09-18
Last Modified: 2012-09-21

I have a dataset with two tables "PatientRegnLabAdviseTemplate" and "PatientRegnLabAdivseRep"

During runtime for certain condition i have to  filter "PatientRegnLabAdviseTemplate"  and add the filtered rows to "PatientRegnLabAdivseRep" .

I am using the following code.

Dim dvTemplatelist As DataView

            dvTemplatelist = ds.Tables("PatientRegnLabAdviseTemplate").DefaultView
            dvTemplatelist.RowFilter = "Investigationcode = " & fgInvList.GetDataDisplay  
                                                          (fgInvList.Row, "Investigationcode")
            dvTemplatelist.Sort = "Parametercode Asc"

            For i = 0 To dvTemplatelist.Count - 1

                Dim newrow As DataRow = ds.Tables("PatientRegnLabAdivseRep").NewRow

                newrow("Caseid") = fgInvList.GetDataDisplay(fgInvList.Row, "Investigationcode")
                newrow("AdviseSerialno") = fgInvList.GetDataDisplay(fgInvList.Row, "Serialno")
                newrow("Parametercode") = dvTemplatelist(i).Item("Parametercode")
                newrow("Parameter") = dvTemplatelist(i).Item("Parameter")
                newrow("Reportno") = ""
                newrow("DateofReport") = ""
                newrow("Value") = ""
                newrow("Remarks") = ""


            dvTemplatelist.RowFilter = ""

when i run this i am getting the error at  
Dim newrow As DataRow = ds.Tables("PatientRegnLabAdivseRep").NewRow

as "Null reference exception found" object reference not set to instance of object.

Can some expert help me to resolove this problem.
Question by:venkataramanaiahsr
    LVL 39

    Accepted Solution


    try this

    Dim newrow As DataRow = ds.Tables("PatientRegnLabAdivseRep").NewRow()
    LVL 39

    Expert Comment

    by:Pratima Pharande
    other reason might be
    check of ds is null
    if ds is null then also you will get this error
    LVL 83

    Expert Comment

    Are you sure that table name PatientRegnLabAdivseRep exists in the dataset? Does it work if you use index instead?

    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    Article by: Kraeven
    Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video discusses moving either the default database or any database to a new volume.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now