Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anyone help me to solve this error
int id = Convert.ToInt32(Request.QueryString["@ID"].ToString());
SqlCommand cmd = new SqlCommand("ups_JoinRegistrationAll", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@ID", SqlDbType.Int).Value = id;
    //.Value = id;
cmd.Connection = con;
con.Open();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dlProfile.DataSource = dt;
dlProfile.DataBind();
cmd.Dispose();
con.Close();


hi am getting error in this code ..error is "
Input string was not in a correct format" for first line.
 int id = Convert.ToInt32(Request.QueryString["@ID"].ToString());
Posted
Updated 21-Dec-11 6:05am
v2
Comments
Tech Code Freak 28-Dec-11 0:54am    
Please let everyone know whether your problem has been solved.
If any of the answers below has helped you in solving it, plz Accept that answer or reply with the result.

Try this:
First change the queryString parameter @ID to ID. Then...

C#
string qstr = String.Empty;
int id=0;
if(Request.QueryString["ID"]!=null && Request.QueryString["ID"]!=String.Empty)
{
  qstr=Request.QueryString["ID"].ToString();
  try
  {
    id=Convert.ToInt32(qstr);
  }
  catch(FormatException fe)
  {
    Label1.Text = "Invalid format. qstr= "+qstr+"  Error is-->"+fe.Message;
  }
}
else
{
  Label1.Text="QueryString Parameter ID is null.";
}


Reply with result/success.
 
Share this answer
 
v3
Comments
RaviRanjanKr 22-Dec-11 17:06pm    
5+
Hi

you can use Below Code.

using that you can parse the any value.

int id
int.TryParse(Request.QueryString["@ID"].ToString(), out id);
 
Share this answer
 
v2
What it is complaining about is that your Request.QueryString is not a valid integer - you will have to look at the vlaue you are passing to the Parse method to work out why - we don't know what is in your data.

Use the debugger - put a breakpoint on teh line and examine the variables - or output it to a label instead so you can see it.
 
Share this answer
 
hi I think you not used @ in below redirect page

C#
Response.Redirect("zz.aspx?ID="xx");


and in this page you have given ur procedure paramter to querystring

C#
request.querystring["ID"].ToString();
 
Share this answer
 
Hi,

Example:

C#
Response.Redirect("DisplayPage.aspx?ID=" + "12345");


In your DisplayPage change:
C#
int id = Convert.ToInt32(Request.QueryString["@ID"].ToString());.

with

C#
int id = Convert.ToInt32(Request.QueryString["ID"].ToString());.


Regards,
 
Share this answer
 
Comments
ythisbug 21-Dec-11 4:15am    
still m getting same error..
Al Moje 21-Dec-11 4:25am    
Replace
cmd.parameters.add(param);
with:

cmd.Parameters.Add("@ID", SqlDbType.Int).Value = id;
Hi,

Make it simple code:
Example:

C#
int id = Convert.ToInt32(Request.QueryString["ID"].ToString());
         DataTable dt = new DataTable();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add("@ID", SqlDbType.Int).Value = id;
         try
         {
             using (conn = new SqlConnection(con))
             {
                 SqlDataAdapter da = new SqlDataAdapter("ups_JoinRegistrationAll", conn);
                 da.Fill(dt);
                 da.Dispose();
             }
         }
         catch (Exception ex)
         {
             throw ex;
         }
         dlProfile.DataSource = dt;
         dlProfile.DataBind();
         cmd.Dispose();


Hope this could help...

Regards,
 
Share this answer
 
v2
Comments
ythisbug 21-Dec-11 5:38am    
no dude...nt wrkng
use this code
int id = Convert.ToInt32(Request.QueryString["@ID"].ToString());
SqlCommand cmd = new SqlCommand();
SqlParameter param = new  SqlParameter;
param.parameterName="@ID";
param.value=id;
con.Open();
cmd.connection=con;
cmd.commandText="ups_JoinRegistrationAll"
cmd.CommandType = CommandType.StoredProcedure;
cmd.parameters.add(param);
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dlProfile.DataSource = dt;
dlProfile.DataBind();
con.Close();
cmd.Dispose();
 
Share this answer
 
v3
Comments
ythisbug 21-Dec-11 4:16am    
still m getting same error..
I think the variable query string should not have the @ symbol

OR

The value passed to the variable in Query String is not being passed as an integer
 
Share this answer
 
v2
You have 2 issues here.
1) The name of your field in the querystring would be better written without the @ symbol.
2) If the querystring argument specified does not exist, then it returns an empty string which is an invalid format for the Convert.ToInt32 method.

To fix this, wrap the querystring argument retrieval like this.
C#
int id;
if( Request.QueryString["ID"] != null )
{
    if( !Int32.TryParse( Request.QueryString["ID"].ToString(), out id )
        id = 0;
}
else
{
    id = 0;
}


Your call would look something like http://www.YourSite/YourPage.aspx?ID=100
If someone accidentally uses something like http://www.YourSite/YourPage.aspx?ID=100 then the code above will still work.
 
Share this answer
 
Comments
ythisbug 24-Dec-11 0:08am    
YourPage.aspx?ID=" i changed to this..its working..
Response.Redirect("myPage.aspx?ID=");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900