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 ChoudharyRank #80 · 24.4K reputationPosted May 18, 2015, 2:43 AM EDT
Sneha Sneha77 reputationPosted May 17, 2015, 11:34 PM EDT
Manoj BhoirRank #599 · 4K reputationPosted May 14, 2015, 8:56 PM EDT
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
Deepak Ratan175 reputationPosted May 14, 2015, 9:05 PM EDT
Its showing an error as there is no UName column
Sneha Sneha77 reputationPosted May 14, 2015, 9:11 PM EDT
Deepak Ratan175 reputationPosted May 14, 2015, 9:33 PM EDT
Error,
According to my Query If i am giving number instance of a.PostId
it working fine, but i have to pass as parameter
Manoj BhoirRank #599 · 4K reputationPosted May 14, 2015, 11:28 PM EDT
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