Click here to Skip to main content
15,896,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class user_apointmentTicketPrint : System.Web.UI.Page
{
    Class1 ob = new Class1();
    protected void Page_Load(object sender, EventArgs e)
    {
        ob.conn();
            string pno = Session["pno"].ToString();
        ob.fetch("select * from patient_reg where pname='" + pno + "'");
        lblpno.Text = ob.ds.Tables[0].Rows[0].ItemArray[0].ToString();
        lbldrname.Text = ob.ds.Tables[0].Rows[0].ItemArray[7].ToString();
        lbldept.Text = ob.ds.Tables[0].Rows[0].ItemArray[6].ToString();
        lblpname.Text = ob.ds.Tables[0].Rows[0].ItemArray[1].ToString();
        lblage.Text = ob.ds.Tables[0].Rows[0].ItemArray[4].ToString();
        lblplace.Text = ob.ds.Tables[0].Rows[0].ItemArray[10].ToString();
    }
}
Posted
v3
Comments
Tom Marvolo Riddle 18-Mar-14 4:00am    
In which line?

Refer the most popular answer by Sergey "Object Reference not set to Instance of an object", please see the code below.[^].

Moreover, before using any property like Session, check if that is null or not.
 
Share this answer
 
v2
Check if one of the following are null -
C#
ob.fetch("select * from patient_reg where pname='" + pno + "'");
       lblpno.Text = ob.ds.Tables[0].Rows[0].ItemArray[0].ToString();
       lbldrname.Text = ob.ds.Tables[0].Rows[0].ItemArray[7].ToString();
       lbldept.Text = ob.ds.Tables[0].Rows[0].ItemArray[6].ToString();
       lblpname.Text = ob.ds.Tables[0].Rows[0].ItemArray[1].ToString();
       lblage.Text = ob.ds.Tables[0].Rows[0].ItemArray[4].ToString();
       lblplace.Text = ob.ds.Tables[0].Rows[0].ItemArray[10].ToString();


Since you are using ToString on all of them, null will throw errors.
Try using Convert.ToString() instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900