Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

Adding new rows to the existing dataset table in vb2010.net

Hi

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") = ""
                ds.Tables("PatientRegnLabAdivseRep").Rows.Add(newrow)

            Next

            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.
0
venkataramanaiahsr
Asked:
venkataramanaiahsr
  • 2
1 Solution
 
Pratima PharandeCommented:
http://www.homeandlearn.co.uk/net/nets12p10.html

try this

Dim newrow As DataRow = ds.Tables("PatientRegnLabAdivseRep").NewRow()
0
 
Pratima PharandeCommented:
other reason might be
check of ds is null
if ds is null then also you will get this error
0
 
CodeCruiserCommented:
Are you sure that table name PatientRegnLabAdivseRep exists in the dataset? Does it work if you use index instead?
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now