error:
Procedure or Function 'GetWidth' expects parameter '@WidthID', which was not supplied.
Can anyone help please?
code behind:
[code]
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string widthId =
Server.UrlEncode(form.SelectedValue.ToString());
Response.Redirect(Link.ToWidth(widthId));
}[/code]
The Link class:
[code]
private static string BuildAbsolute(string relativeUri)
{
// get current uri
Uri uri = HttpContext.Current.Request.Url;
// build absolute path
string app = HttpContext.Current.Request.ApplicationPath;
if (!app.EndsWith("/")) app += "/";
relativeUri = relativeUri.TrimStart('/');
// return the absolute path
return HttpUtility.UrlPathEncode(
String.Format("http://{0}:{1}{2}{3}",
uri.Host, uri.Port, app, relativeUri));
}
// generate a width URL
public static string ToWidth(string widthId)
{
return BuildAbsolute(String.Format("WidthAdmin.aspx?Width={0}", widthId));
}
[/code]
Amit ChoudharyPosted Feb 16, 2010, 6:48 AM
private void BindGrid()
{
string widthId =
Server.UrlDecode(Request.QueryString["WidthID"]);
// get a DataTable object containing the catalog departments
grid.DataSource = CatalogAccess.GetWidth(widthId);
// bind the data bound controls to the data source
grid.DataBind();
}
in this method your function GetWidth() is seems to be culprit for the error... so do one thing double check your
Code inside the GetWidth(). Well i have designed the body of Getwidth() hope it works for you.
Sarah NelPosted Feb 16, 2010, 5:33 AM
Procedure or Function 'GetWidth' expects parameter '@WidthID', which was not supplied.
Stack Trace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at GenericDataAccess.ExecuteSelectCommand(DbCommand command) in c:\Inetpub\wwwroot\Tyres\App_Code\GenericDataAccess.cs:line 44
at CatalogAccess.GetWidth(String id) in c:\Inetpub\wwwroot\Tyres\App_Code\CatalogAccess.cs:line 36
at WidthAdmin.Page_Load(Object sender, EventArgs e) in c:\Inetpub\wwwroot\Tyres\WidthAdmin.aspx.cs:line 20
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Amit ChoudharyPosted Feb 16, 2010, 5:01 AM
if you can post the snap shot of your Error or Copy paste the error [Complete Page including stack trace] you are getting while running your program.
it'll help to get the source of error..
Sarah NelPosted Feb 16, 2010, 4:43 AM
I have tried this as well, which doesn't work I get the same error:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string widthId =
Server.UrlEncode(form.SelectedValue.ToString());
Response.Redirect(Link.ToWidth(widthId));
string connectionString =
System.Configuration.ConfigurationManager.ConnectionStrings["Tyres"].ConnectionString;
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand("GetWidth",
connection))
{
connection.Open();
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("@WidthID", widthId);
command.ExecuteNonQuery();
}
}
}
The parameter does pass to the next page if a do not populate the gridview, maybe the problem is in receiving the parameter
protected void Page_Load(object sender, EventArgs e)
{
// load the grid only the first time the page is loaded
if (!Page.IsPostBack)
{
// load the department grid
BindGrid();
}
}
// populate the grid view with data
private void BindGrid()
{
string widthId =
Server.UrlDecode(Request.QueryString["WidthID"]);
// get a DataTable object containing the catalog departments
grid.DataSource = CatalogAccess.GetWidth(widthId);
// bind the data bound controls to the data source
grid.DataBind();
}
kiran kumarPosted Feb 16, 2010, 4:35 AM