Trying to get currently logged in users userid and use it in an SQL query from behindcode to fill a gridview but its not working any ideas what I'm doing wrong. I keep getting a null value error. Also I'm trying to only use the Microsoft.AspNet.Identity if thats even possible
pageload
if (!IsPostBack)
{
SqlDataSource SqlDataSource1 = new SqlDataSource();
SqlDataSource1.ID = "SqlDataSource1";
this.Page.Controls.Add(SqlDataSource1);
SqlDataSource1.InsertParameters["luser"].DefaultValue = User.Identity.GetUserId();
SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlDataSource1.SelectCommand = "SELECT top 3 UserId, Friending from Friendreq Where Friending = @luser";
GridView1.DataSource = SqlDataSource1;
GridView1.DataBind();
}
UPDATE:
I was able to get the results that i wanted by adding the requested directly into the SQL query. Is there any reason that i should not add it that what
SqlDataSource SqlDataSource1 = new SqlDataSource();
SqlDataSource1.ID = "SqlDataSource1";
this.Page.Controls.Add(SqlDataSource1);
SqlDataSource1.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlDataSource1.SelectCommand = "SELECT top 3 UserId, Friending from Friendreq Where Friending = '"+User.Identity.GetUserId()+"'";
GridView1.DataSource = SqlDataSource1;
GridView1.DataBind();
Solution = Friending = '"+User.Identity.GetUserId()+"'";