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;
[DataMember]
public User uname1
{
get { return Name1; }
set { Name1 = value; }
}
:
......so on
}
And here is the class User
public class User
{
string User_ID = "";
string Name = "";
string City = "";
string Address = "";
string Premises = "";
string Email_ID = "";
[DataMember]
public string name
{
get { return Name; }
set { Name = value; }
}
:
......so on
}
Following are my codes where I want to access the above via SqlDataReader.
SqlConnection con = new SqlConnection(GetConnectionString());
con.Open();
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())
{c1.uname1.name = sdr["Name"].ToString();
c1.uname1.address = sdr["Address"].ToString();
c1.date = 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();
cmp.Add(c1);
}
sdr.Close();
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.