Link to home
Start Free TrialLog in
Avatar of Amjad Fiaz
Amjad Fiaz

asked on

Failed to convert parameter value from a String to a Int32.

<b>I'm trying</b>
                         int ist = EAdapter.Insert(txtclgname.Text,
                         txtErlno.Text, drpsem.SelectedItem.Text, drpEdu.SelectedItem.Text, drpBranch.SelectedItem.Text,
                         drpPassyear.SelectedItem.Text, float.Parse(txtCGPA.Text), drpreqskill.SelectedItem.Text, txtExSkill.Text, resume);


<b>how to fixed it</b>
Avatar of HainKurt
HainKurt
Flag of Canada image

pass valid data to your procedure...

if you send "THIS_IS_NOT_A_NUMBER" for a integer parameter, of course you will get error...
if all your parameters are correct, then make sure this function "EAdapter.Insert(...)" returns integer value all the time...

or try

string ist = EAdapter.Insert(...);

Open in new window


to see if it works...
Avatar of Amjad Fiaz
Amjad Fiaz

ASKER

Its Not Working
Hi Amjad Fiaz,        

Could you please try the below code and confirm.

    int ist = Convert.ToInt32(EAdapter.Insert(txtclgname.Text, txtErlno.Text, drpsem.SelectedItem.Text, drpEdu.SelectedItem.Text, drpBranch.SelectedItem.Text,
            drpPassyear.SelectedItem.Text, float.Parse(txtCGPA.Text), drpreqskill.SelectedItem.Text, txtExSkill.Text, resume));

Open in new window

Its Not Working
meaning what? what error mesage do you get?

put a breakpoint on that line

EAdapter.Insert(...)

and check all parameter values...
are they correct?
what does that function return, an integer, are you sure?
what is code for that function?
If possible could you please share us the more code ?
protected void btnsbmit_Click(object sender, EventArgs e)
        {

            lblEdu.Text = "";
            lblBranch.Text = "";
            lblPassyr.Text = "";
            lblSkill.Text = "";
            lblmsg.Text = "";
            lblResume.Text = "";
            if (drpsem.SelectedIndex == 0)
            {
                lblsem.Text = "!!!";
            }
            else if (drpEdu.SelectedIndex == 0)
            {
                lblEdu.Text = "!!!";
            }
            else if (drpBranch.SelectedIndex == 0)
            {
                lblBranch.Text = "!!!";

            }
            else if (drpPassyear.SelectedIndex == 0)
            {
                lblPassyr.Text = "!!!";

            }
            else if (drpreqskill.SelectedIndex == 0)
            {
                lblSkill.Text = "!!!";
            }

            else
            {
                if (FUResume.HasFile)
                {
                    FUResume.SaveAs(Server.MapPath("~/Resume/" + FUResume.FileName.ToString()));
                    string resume = "~/Resume/" + FUResume.FileName.ToString();
                    var test = Convert.ToInt32(Session["SID"]);
                    int ist = Convert.ToInt32(EAdapter.Insert(txtclgname.Text, txtErlno.Text, drpsem.SelectedItem.Text,
                        drpEdu.SelectedItem.Text, drpBranch.SelectedItem.Text,
                  drpPassyear.SelectedItem.Text, float.Parse(txtCGPA.Text), drpreqskill.SelectedItem.Text, txtExSkill.Text, resume));

                    if (ist == 1)
                    {
                        lblmsg.Text = "Add successfully..";
                        clean();
                        Response.Redirect("Home.aspx");
                    }

                }
                else
                {
                    lblResume.Text = "!!!";
                    lblEdu.Text = "";
                    lblBranch.Text = "";
                    lblPassyr.Text = "";
                }
            }
        }
this is show (System.FormatException: Input string was not in a correct format.)
1. whats the result of

string ist = EAdapter.Insert(...)

2. what is code for this function: EAdapter.Insert(..) at least specification + return part
hi Amjad Fiaz,

could you please change the data type from int to var   and check which value is coming

 var ist = EAdapter.Insert(txtclgname.Text, txtErlno.Text, drpsem.SelectedItem.Text,
                      drpEdu.SelectedItem.Text, drpBranch.SelectedItem.Text,
                   drpPassyear.SelectedItem.Text, float.Parse(txtCGPA.Text), drpreqskill.SelectedItem.Text, txtExSkill.Text, resume);

Open in new window

@Tapan

I already suggested this

string ist = EAdapter.Insert(...)

and still waiting for answer... anything can be converted to string... so it does not fail...
HainKurt It show error argument  over loaded..
It Show same error System.FormatException: Input string was not in a correct format....
Tapan
It show error argument  over loaded..

could not get what this mean

when you use this and run

string ist = EAdapter.Insert(...)

what is happening?

also, when you put a breakpoint here, what are all the values you are passing?
also, what is the code for that function? (spec + return part at least)
check number of parameters are same or different for the method EAdapter.Insert(....)
so, original error goes and now this one...
check your function for parameters, and pass appropriate values
and check return type of that function and use that type in your calling code...
what is EAdapter, do you have any manual? looks like it is a 3rd party product to me...

and why you did not share the code for that function so far?
this._adapter.InsertCommand.CommandText = "dbo.INSERT_ADDEDU";
            this._adapter.InsertCommand.CommandType = global::System.Data.CommandType.StoredProcedure;
            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RETURN_VALUE", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.ReturnValue, 10, 0, null, global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@SID", global::System.Data.SqlDbType.Int, 4, global::System.Data.ParameterDirection.Input, 10, 0, "SID", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@CLGNAME", global::System.Data.SqlDbType.NVarChar, 256, global::System.Data.ParameterDirection.Input, 0, 0, "CollegeName", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@ERNO", global::System.Data.SqlDbType.NVarChar, 256, global::System.Data.ParameterDirection.Input, 0, 0, "EnrallNo", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@SEMESTER", global::System.Data.SqlDbType.NVarChar, 256, global::System.Data.ParameterDirection.Input, 0, 0, "semester", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@EDUCATION", global::System.Data.SqlDbType.NVarChar, 256, global::System.Data.ParameterDirection.Input, 0, 0, "Education", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@BRANCH", global::System.Data.SqlDbType.NVarChar, 256, global::System.Data.ParameterDirection.Input, 0, 0, "Branch", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@PASSYEAR", global::System.Data.SqlDbType.NVarChar, 256, global::System.Data.ParameterDirection.Input, 0, 0, "PassYear", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));

            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@CGPA", global::System.Data.SqlDbType.Float, 8, global::System.Data.ParameterDirection.Input, 53, 0, "CGPA", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@SKILL", global::System.Data.SqlDbType.NVarChar, 256, global::System.Data.ParameterDirection.Input, 0, 0, "Skill", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@EXSKILL", global::System.Data.SqlDbType.NVarChar, 256, global::System.Data.ParameterDirection.Input, 0, 0, "Skill", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.InsertCommand.Parameters.Add(new global::System.Data.SqlClient.SqlParameter("@RESUME", global::System.Data.SqlDbType.NVarChar, 256, global::System.Data.ParameterDirection.Input, 0, 0, "Resume", global::System.Data.DataRowVersion.Current, false, null, "", "", ""));
            this._adapter.UpdateCommand = new global::System.Data.SqlClient.SqlCommand();
            this._adapter.UpdateCommand.Connection = this.Connection;
 SDS.SELECT_ADDEDUDataTable EDT = new SDS.SELECT_ADDEDUDataTable();
        SDSTableAdapters.SELECT_ADDEDUTableAdapter EAdapter = new SDSTableAdapters.SELECT_ADDEDUTableAdapter();
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.