Please i need help to correct this error
error
Server Error in '/' Application.
Procedure or function 'GetMessage' expects parameter '@UserName', which was not supplied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Procedure or function 'GetMessage' expects parameter '@UserName', which was not supplied.
Source Error:
Line 62: catch (Exception ex)
Line 63: {
Line 64: throw ex;
Line 65: }
Line 66: }
amended code
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ToString());
// string constrr = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
//string con;
protected void Page_Load(object sender, EventArgs e)
{
if (this.Page.User.Identity.IsAuthenticated)
{
string username = this.Page.User.Identity.Name;
//pnlcomment.Visible = true;
// Session["Name"] = Session["Name"].ToString();
if (!IsPostBack)
{
BindDatalist(username);
}
}
}
public void BindDatalist(string username)
{
try
{
SqlDataAdapter adp = new SqlDataAdapter("GetMessage", con);
adp.SelectCommand.CommandType = CommandType.StoredProcedure;
// cmd.Parameters.AddWithValue("@UserName", username);
DataTable dt = new DataTable();
adp.Fill(dt);
if (dt.Rows.Count > 0)
{
GetMergedAll.DataSource = dt;
GetMergedAll.DataBind();
}
}
catch (Exception ex)
{
throw ex;
}
}
protected void GetMergedAll_ItemCommand(object source, DataListCommandEventArgs e)
{
try
{
if (e.CommandName == "Insert")
{
TextBox txtcomments = (TextBox)e.Item.FindControl("txtComments");
// TextBox txtaddress = (TextBox)e.Item.FindControl("txtsaddress");
// TextBox txtrollno = (TextBox)e.Item.FindControl("txtsrollno");
SqlCommand cmd = new SqlCommand("GetUSERcomment", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Comments", txtcomments.Text);
cmd.Parameters.AddWithValue("@UserName", this.Page.User.Identity);
// cmdd.Parameters.AddWithValue("@rollno",txtrollno.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
cmd.Dispose();
Response.Write("<script type=\"text/javascript\">alert('Inserted Successfully!!!');</script>");
// BindDatalist(username);
}
}
catch (Exception ex)
{
throw ex;
}
}