Newbie10 Newbie10 - 21 days ago 7
SQL Question

Display Table from database to gridview

I am developing an online reservation and from the client's page I want his transactions to be viewed via gridview, but program returns an error and it says that "Additional information: Procedure or function 'JoinRoomSubPayment' expects parameter '@USERNAME', which was not supplied."

here is my code:

Sql:

SELECT USERNAME, FIRST_NAME, LAST_NAME, BIRTHDAY, CONTACT_NUMBER, EMAIL_ADDRESS, HOME_ADDRESS FROM TBL_Client
WHERE USERNAME = @USERNAME


ClassDisplaySummary.cs:

public DataSet _JoinRoomSubPayment(string user){
conn.Open();
SqlCommand cmd = new SqlCommand("JoinRoomSubPayment", conn);
cmd.Parameters.Add("@USERNAME", SqlDbType.VarChar).Value = user;
cmd.ExecuteNonQuery();
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds.Clear();
da.Fill(ds, "_JoinRoomSubPayment");
conn.Close();
return ds;}


ClientPage.aspx.cs:

user = Session["username"].ToString();
SummaryGView.DataSource = cd._JoinRoomSubPayment(user).Tables["_JoinRoomSubPayment"];
SummaryGView.DataBind();


Any Help would be appreciated

Answer

Your statement seems correct this error may occur due to cmd.ExecuteNonQuery(); remove this line from your code and then try

public DataSet _JoinRoomSubPayment(string user){
conn.Open();
SqlCommand cmd = new SqlCommand("JoinRoomSubPayment", conn);
cmd.Parameters.Add("@USERNAME", SqlDbType.VarChar).Value = user;
// cmd.ExecuteNonQuery(); remove this line from your code 
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds.Clear();
da.Fill(ds, "_JoinRoomSubPayment");
conn.Close();
return ds;}
Comments