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
WHERE
condition in yourSELECT
query which saysWHERE Username = Username
which is aTAUTOLOGY
and will always beTRUE
and so fetching all rows.In essence your
SELECT
query is just doingYou need to specify the logged in customerid in
WHERE
condition to get his/her record.Considering that you have a variable named
Username
in yourASP.NET
code where you have stored current logged in customer name; then change your code like below