here is my viewprofile.aspx code where the binding will take place. im planning to bind my data in sql to my gridview but it is showing me all of the data(from sql) instead of that of the specific logged in customer. Here is my code:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["New"] != null)
{
bindgrid();
}
}
public void bindgrid()
{
SqlConnection conn = new SqlConnection("Data Source = 'PAULO'; Initial Catalog=ShoppingCartDB;Integrated Security =True");
SqlCommand cmd = new SqlCommand("select * from UserData WHERE Username = Username ", conn);
SqlDataAdapter da = new SqlDataAdapter("", conn);
da.SelectCommand = new SqlCommand("select * from UserData WHERE Username = Username", conn);
DataSet ds = new DataSet();
da.Fill(ds, "data");
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
That's because of the
WHEREcondition in yourSELECTquery which saysWHERE Username = Usernamewhich is aTAUTOLOGYand will always beTRUEand so fetching all rows.In essence your
SELECTquery is just doingYou need to specify the logged in customerid in
WHEREcondition to get his/her record.Considering that you have a variable named
Usernamein yourASP.NETcode where you have stored current logged in customer name; then change your code like below