protected void statusgrdview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblPostID = (Label)e.Row.FindControl("lblPostID");
string postID = lblPostID.Text;
DataSet ds = new DataSet();
con.Open();
stringcm dstr = "select a.comments,b.UName as CreatedBy from TBL_FBComment a inner join TBL_FBLogin b on a.CreatedBy=b.EmpID and a.CommentID=a.PostID";
SqlCommand cmd = new SqlCommand(cmdstr, con);
cmd.Parameters.AddWithValue("@PostID", postID);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
cmd.ExecuteNonQuery();
con.Close();
try
{
ListView inner = e.Row.FindControl("ListView1") as ListView;
inner.DataSource = ds.Tables[0];
inner.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}

Pankaj Kumar ChoudharyPosted May 18, 2015, 6:43 AM
Sneha SnehaPosted May 18, 2015, 3:34 AM
Manoj BhoirPosted May 15, 2015, 3:28 AM
select a.comments,b.UName as CreatedBy from TBL_FBComment a inner join TBL_FBLogin b on a.CreatedBy=b.EmpID
and a.CommentID=a.PostID
Where a.PostID = @PostID
Deepak RatanPosted May 15, 2015, 1:33 AM
Error,
According to my Query If i am giving number instance of a.PostId
it working fine, but i have to pass as parameter
Sneha SnehaPosted May 15, 2015, 1:11 AM
Deepak RatanPosted May 15, 2015, 1:05 AM
Its showing an error as there is no UName column
Manoj BhoirPosted May 15, 2015, 12:56 AM
CreatedBy is a alias you defined for column UName. While performing Inner Join Column Name you are using for Join should be actual Column Name present in your Table or you have to use main query and sub query concept.
Your query should be :
select a.comments,b.UName as CreatedBy
from TBL_FBComment a
inner join TBL_FBLogin b
on a.UName=b.EmpID
and a.CommentID=a.PostID