Q:

passing a parameter to GridView when calling data from database

so my GridView Returns all the data in my Table but i want to return data that are related to the  UserName attribute in the table,mind you that i have Multiple UserName's in the table.
i tried giving my function a string username and in my page_load: 
string SessionName;
protected void Page_Load(object sender, EventArgs e)
{
    SessionName = Session["Username"].ToString();
    DataSet ds = InsertClass.GetCart(SessionName);

}

in my class:
public static DataSet GetCart(string UserName)
{
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ToString());
    conn.Open();
    SqlCommand cmd = new SqlCommand("SELECT * FROM [ShoppingCart] WHERE UserName = @UserName ", conn);
    cmd.CommandType = CommandType.Text;

    cmd.Parameters.Add(new SqlParameter("@UserName", UserName));

    DataSet ds = new DataSet();
    SqlDataAdapter adapter1 = new SqlDataAdapter(cmd);
    adapter1.Fill(ds);
    conn.Close();
    return ds;
}

Edit:my mistake guys i didnt add the parameter to my function because i was trying alot of things before i asked the question and forgot to put it back.

A:

You are not passing username as string parameter here in your code public static DataSet GetCart() 
Here is correct one:
public static DataSet GetCart(string userName)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ToString());
        conn.Open();
        SqlCommand cmd = new SqlCommand("SELECT * FROM [ShoppingCart] WHERE UserName = @UserName ", conn);
        cmd.CommandType = CommandType.Text;

        cmd.Parameters.AddWithValue("@UserName", userName);

        DataSet ds = new DataSet();
        SqlDataAdapter adapter1 = new SqlDataAdapter(cmd);
        adapter1.Fill(ds);
        conn.Close();
        return ds;
    }

