Why doesn't this work?

  • Thread starter Thread starter Looch
  • Start date Start date
L

Looch

Hi all,

I get a 'input string was not in a correct format' error on the second
line of code here. The sproc defines the '@quan5x7' as int.

sqlCmd.Parameters.Add("@quan5x7", SqlDbType.Int);
sqlCmd.Parameters[21].Value = Convert.ToInt32(cmbQuan5x7.Text);

The SqlDbType.Int is equal to System.Int32 correct?

Using C# Express and SQL 2005 Express. Thanks for any insight.
 
Looch said:
Hi all,

I get a 'input string was not in a correct format' error on the second
line of code here. The sproc defines the '@quan5x7' as int.

sqlCmd.Parameters.Add("@quan5x7", SqlDbType.Int);
sqlCmd.Parameters[21].Value = Convert.ToInt32(cmbQuan5x7.Text);

The text of the control is a value that can not be converted to an int.
 
Looch said:
Hi all,

I get a 'input string was not in a correct format' error on the second
line of code here. The sproc defines the '@quan5x7' as int.

sqlCmd.Parameters.Add("@quan5x7", SqlDbType.Int);
sqlCmd.Parameters[21].Value = Convert.ToInt32(cmbQuan5x7.Text);

The SqlDbType.Int is equal to System.Int32 correct?

Using C# Express and SQL 2005 Express. Thanks for any insight.

My initial guess is that cmbQuan5x7.Text does not contain a value that
can be converted to an int.
 
Hi all,

I get a 'input string was not in a correct format' error on the second
line of code here. The sproc defines the '@quan5x7' as int.

sqlCmd.Parameters.Add("@quan5x7", SqlDbType.Int);
sqlCmd.Parameters[21].Value = Convert.ToInt32(cmbQuan5x7.Text);

The SqlDbType.Int is equal to System.Int32 correct?

Using C# Express and SQL 2005 Express. Thanks for any insight.

I'm guessing the 21st SqlParameter isn't what you think it is, try

sqlCmd.Parameters["@quan5x7"].Value = Convert.ToInt32(cmbQuan5x7.Text);
 
Looch said:
I get a 'input string was not in a correct format' error on the second
line of code here. The sproc defines the '@quan5x7' as int.

sqlCmd.Parameters.Add("@quan5x7", SqlDbType.Int);
sqlCmd.Parameters[21].Value = Convert.ToInt32(cmbQuan5x7.Text);

The SqlDbType.Int is equal to System.Int32 correct?

Well, they're not the same type - but the chances are that the problem
is really that cmbQuan5x7.Text can't be parsed as an integer.
 
Hi,

Looch said:
Hi all,

I get a 'input string was not in a correct format' error on the second
line of code here. The sproc defines the '@quan5x7' as int.

sqlCmd.Parameters.Add("@quan5x7", SqlDbType.Int);
sqlCmd.Parameters[21].Value = Convert.ToInt32(cmbQuan5x7.Text);

The SqlDbType.Int is equal to System.Int32 correct?

not the same, but you have a defined conversion.

The problem most probably is cause cmbQuan5x7.Text is not an integer value
 
Morten said:
Hi all,

I get a 'input string was not in a correct format' error on the second
line of code here. The sproc defines the '@quan5x7' as int.

sqlCmd.Parameters.Add("@quan5x7", SqlDbType.Int);
sqlCmd.Parameters[21].Value = Convert.ToInt32(cmbQuan5x7.Text);

The SqlDbType.Int is equal to System.Int32 correct?

Using C# Express and SQL 2005 Express. Thanks for any insight.

I'm guessing the 21st SqlParameter isn't what you think it is, try

sqlCmd.Parameters["@quan5x7"].Value = Convert.ToInt32(cmbQuan5x7.Text);
Did you mean 22nd?

Cheers,

Cliff
 
Morten said:
Hi all,

I get a 'input string was not in a correct format' error on the second
line of code here. The sproc defines the '@quan5x7' as int.

sqlCmd.Parameters.Add("@quan5x7", SqlDbType.Int);
sqlCmd.Parameters[21].Value = Convert.ToInt32(cmbQuan5x7.Text);

The SqlDbType.Int is equal to System.Int32 correct?

Using C# Express and SQL 2005 Express. Thanks for any insight.

I'm guessing the 21st SqlParameter isn't what you think it is, try

sqlCmd.Parameters["@quan5x7"].Value = Convert.ToInt32(cmbQuan5x7.Text);
Did you mean 22nd?

Cheers,

Cliff

Ah, a bit hasty there :) Anyhow, the most likely cause for his error isprobably empty Text property or a Text property containing something other than an integer value.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top