Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using Fobbs.Logic;
using System.Globalization;
using System.Threading.Tasks;

namespace Fobbs
{
    public partial class Eng1 : System.Web.UI.Page
    {
        IndexLogic il = new IndexLogic();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Aieebind();

            }
        }

        void Aieebind()
        {
            DataSet ds = new DataSet();
            ds = il.FetchData(1);
            DDLAieee.DataSource = ds.Tables[0];
            DDLAieee.DataBind();
            DDLAieee.Items.Insert(0, new ListItem("Select", "Select"));
        }


        protected void DDLAieee_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            ds = il.FetchDataById(2,DDLAieee.SelectedItem.Value);
 
    
            if (ds.Tables[0].Rows.Count > 0)
            {
                txtdescription.Text = ds.Tables[0].Rows[0][1].ToString();
                
            }
        }
    }
}




error come basically in this line:

HTML
ds = il.FetchDataById(2,DDLAieee.SelectedItem.Value);

Input string was not in a correct format.
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.FormatException: Input string was not in a correct format.

Source Error:


Line 38:         {
Line 39:             DataSet ds = new DataSet();
Line 40:             ds = il.FetchDataById(2, Convert.ToInt32(DDLAieee.SelectedItem.Text));
Line 41: 
Line 42:             if (ds.Tables[0].Rows.Count > 0)


Source File: C:\Users\ADI\Documents\Visual Studio 2010\Projects\Fobbs\Fobbs\Eng1.aspx.cs    Line: 40
Posted
Updated 29-Apr-14 18:56pm
v2
Comments
ADI@345 30-Apr-14 0:45am    
pls reply me soon
Tom Marvolo Riddle 30-Apr-14 1:18am    
Try this:
ds = il.FetchDataById(2, Convert.ToInt32(DDLAieee.SelectedItem.Value));

Give DataTextField and DataValueField at below line
C#
DDLAieee.DataSource = ds.Tables[0];
DDLAieee.DataBind();
 
Share this answer
 
Hi Kindly show your FetchDataById Method to us.
 
Share this answer
 
Comments
ADI@345 30-Apr-14 1:12am    
public DataSet FetchDataById(int uid, int id)
{

DataAccess objDataAccess;
DataSet objResult;
objDataAccess = new DataAccess();
List<dbparameter> objArrayList;
DbParameter objParamater;
objArrayList = new List<dbparameter>();

objParamater = objDataAccess.NewParameter();
objParamater.ParameterName = "@uid";
objParamater.DbType = DbType.Int32;
objParamater.Direction = ParameterDirection.Input;
objParamater.Value = uid;
objArrayList.Add(objParamater);

objParamater = objDataAccess.NewParameter();
objParamater.ParameterName = "@id";
objParamater.DbType = DbType.Int32;
objParamater.Direction = ParameterDirection.Input;
objParamater.Value = id;
objArrayList.Add(objParamater);

objResult = objDataAccess.ExecuteQuery("AieeeProc", objArrayList.ToArray());
return objResult;
}
Try this:
C#
ds = il.FetchDataById(2, Convert.ToInt32(DDLAieee.SelectedItem.Value));

Change SelectedItem.Text Into SelectedItem.Value
 
Share this answer
 
v2
Comments
ADI@345 30-Apr-14 1:23am    
I HAVE ALREADY CHANGE TEXT INTO VALUE,BUT ISN'T WORK...
Tom Marvolo Riddle 30-Apr-14 1:24am    
Are you getting the same error again?
ADI@345 30-Apr-14 1:25am    
YES ,I AM GETTING THE SAME ERROR..
Tom Marvolo Riddle 30-Apr-14 1:28am    
Check the result return from query.
Check the selected value in selected index changed event(Text As well as Value)
ADI@345 30-Apr-14 1:32am    
returning value is text not value..
SQL
change the parameter int to string because your value like alpha numeric you have pass string parameter,
Ref:
public DataSet FetchDataById(int uid, string id)
 
Share this answer
 
Comments
ADI@345 30-Apr-14 1:44am    
i have using this,but isn't wrking,,same error arise
ADI@345 30-Apr-14 1:45am    
actualy i have made two folder,first admin,and second website,when we insert data on admin panel,related data will fetch on website using dropdownbox.
oliver grace 30-Apr-14 1:46am    
still you are getting input string error or some other error?
ADI@345 30-Apr-14 2:17am    
yes,i am getting same error again
Try this,Copy and replace this code
C#
protected void DDLAieee_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            ds = il.FetchDataById(2,DDLAieee.SelectedItem.ValueToString());


            if (ds.Tables[0].Rows.Count > 0)
            {
                txtdescription.Text = ds.Tables[0].Rows[0][1].ToString();

            }
        }


public DataSet FetchDataById(int uid, string id)
{

DataAccess objDataAccess;
DataSet objResult;
objDataAccess = new DataAccess();
List objArrayList;
DbParameter objParamater;
objArrayList = new List();

objParamater = objDataAccess.NewParameter();
objParamater.ParameterName = "@uid";
objParamater.DbType = DbType.Int32;
objParamater.Direction = ParameterDirection.Input;
objParamater.Value = uid;
objArrayList.Add(objParamater);

objParamater = objDataAccess.NewParameter();
objParamater.ParameterName = "@id";
objParamater.DbType = DbType.VarChar;
objParamater.Direction = ParameterDirection.Input;
objParamater.Value = id;
objArrayList.Add(objParamater);

objResult = objDataAccess.ExecuteQuery("AieeeProc", objArrayList.ToArray());
return objResult;
}
 
Share this answer
 
Comments
ADI@345 30-Apr-14 2:23am    
objParamater.DbType = DbType.VarChar;
we have getting error in varchar
ADI@345 30-Apr-14 2:26am    
but sir in sql databse we have alread assign id is int.
ADI@345 30-Apr-14 2:38am    
pls reply
oliver grace 30-Apr-14 2:50am    
change int to varchar in sql also
ADI@345 30-Apr-14 3:06am    
thanks a lot,but now i have solve this issue...

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