You must Sign In to post a response.
  • Category: [Competition Entries]

    Join operation in webservice from two classes

    Hi, I want to access the data from two tables via join operation in webservice & assign it to Gridview, My codes are working well only for single table. For second table it's showing Null reference exception.I am using the following codes in webservice class where I have declare a variable Name1 of class User type.

    public class Complaint
    int Complaint_ID = 0;
    DateTime Date = default(DateTime);
    string Product_Description = "";
    string Complaint_Description = "";
    string Action = "";
    string Status = "";
    int User_ID = 0;
    User Name1;

    public User uname1
    get { return Name1; }
    set { Name1 = value; }
    : on
    And here is the class User
    public class User
    string User_ID = "";
    string Name = "";
    string City = "";
    string Address = "";
    string Premises = "";
    string Email_ID = "";
    public string name
    get { return Name; }
    set { Name = value; }
    : on

    Following are my codes where I want to access the above via SqlDataReader.
    SqlConnection con = new SqlConnection(GetConnectionString());
    string sel = "select cust.Name,cust.Address,comp.Date, comp.Phone_No,comp.Product_Description,comp.Complaint_Description,comp.Action,comp.Status from Complaint comp join Customers cust on comp.User_ID=cust.User_ID where Complaint_ID='" +this.Textbox1.Text+"'";
    SqlCommand cmd = new SqlCommand(sel,con);
    List<Complaint> cmp = new List<Complaint>();
    SqlDataReader sdr = cmd.ExecuteReader();
    while (sdr.Read())
    { = sdr["Name"].ToString();
    c1.uname1.address = sdr["Address"].ToString(); = Convert.ToDateTime(sdr["Date"].ToString());
    c1.phoneno = sdr["Phone_No"].ToString();
    c1.productdescription = sdr["Product_Description"].ToString();
    c1.complaintdescription = sdr["Complaint_Description"].ToString();
    c1.action = sdr["Action"].ToString();
    c1.status = sdr["Status"].ToString();
    return cmp;
    Join query is working well in sql white I test, but it's showing error-object reference not set to an instance of an object while I am running it. Please suggest what step I am missing as it's giving NullReference Exception.
  • #756773

    If you are trying to assign null value to object in that case you got this type of error. My suggestion is better to validate the value before assign to object whether the value is null or not based on that condition you should assign the value to object.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #756791

    refer this url

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • Sign In to post your comments