Input string was not in a correct format.

G

Guest

Hi All,
this is the error:
Input string was not in a correct format.

this is the code I am trying to debug:
<code>
string sql = @"
INSERT INTO [User]
(UserID, Login, Password, FirstName, LastName,
PhoneNumber, Email, IsAdministrator, Address,
CellNumber, DateOfBirth)
VALUES
('{0}','{1}','{2}','{3}','{4}',
'{5}','{6}','{7',{8},{9},{10})";

//add required values to replace
values.Add(Guid.NewGuid().ToString());
values.Add(txtLogin.Text);
values.Add(txtPwd.Text);
values.Add(txtFName.Text);
values.Add(txtLName.Text);
values.Add(txtPhone.Text);
values.Add(txtEmail.Text);
values.Add(0); //is administrator

//add the optional values or Null
if (txtAddress.Text != string.Empty)
values.Add("'" + txtAddress.Text + "'");
else
values.Add("Null");

if (txtMobile.Text != string.Empty)
values.Add("'" + txtMobile.Text + "'");
else
values.Add("Null");

if (txtBirth.Text != string.Empty)
values.Add("'" + txtBirth.Text + "'");
else
values.Add("Null");

//format the string with the array of values

sql = String.Format(sql, values.ToArray());
</code>
this is the line where that causes the exception:
sql = String.Format(sql, values.ToArray());

I am not asking anyone to debug my code, I only provide it for purposes of
clarification. What I would like to know, is there any easy to see what the
sql string is before it is inserted into the db.

I am a vb programmer newly exposed to the .net world, the method I used to
solve these type of errors was to create a msgbox that had the string once
it waas built, and then I could tell what was causing the problem. What I am
looking for here is something similair.

Thank You.
 
G

Guest

<smacks head!>

thanks, I guess I did get my code debugged after all, but do you know of any
easy way to see what kind of string I am passing to the sqlCommand object ?

thanks gain.

Kelly Ethridge said:
You're missing the closeing brace '}' after then 7 in the VALUES.

Kelly

ramonred said:
Hi All,
this is the error:
Input string was not in a correct format.

this is the code I am trying to debug:
<code>
string sql = @"
INSERT INTO [User]
(UserID, Login, Password, FirstName, LastName,
PhoneNumber, Email, IsAdministrator, Address,
CellNumber, DateOfBirth)
VALUES
('{0}','{1}','{2}','{3}','{4}',
'{5}','{6}','{7',{8},{9},{10})";

//add required values to replace
values.Add(Guid.NewGuid().ToString());
values.Add(txtLogin.Text);
values.Add(txtPwd.Text);
values.Add(txtFName.Text);
values.Add(txtLName.Text);
values.Add(txtPhone.Text);
values.Add(txtEmail.Text);
values.Add(0); //is administrator

//add the optional values or Null
if (txtAddress.Text != string.Empty)
values.Add("'" + txtAddress.Text + "'");
else
values.Add("Null");

if (txtMobile.Text != string.Empty)
values.Add("'" + txtMobile.Text + "'");
else
values.Add("Null");

if (txtBirth.Text != string.Empty)
values.Add("'" + txtBirth.Text + "'");
else
values.Add("Null");

//format the string with the array of values

sql = String.Format(sql, values.ToArray());
</code>
this is the line where that causes the exception:
sql = String.Format(sql, values.ToArray());

I am not asking anyone to debug my code, I only provide it for purposes of
clarification. What I would like to know, is there any easy to see what the
sql string is before it is inserted into the db.

I am a vb programmer newly exposed to the .net world, the method I used to
solve these type of errors was to create a msgbox that had the string once
it waas built, and then I could tell what was causing the problem. What I am
looking for here is something similair.

Thank You.
 
K

Kelly Ethridge

You could write to the output window using System.Diagnostics.Debug.WriteLine. Or if you have the Windows.Forms loaded you
could use the MessageBox like you used to.

Kelly

ramonred said:
<smacks head!>

thanks, I guess I did get my code debugged after all, but do you know of any
easy way to see what kind of string I am passing to the sqlCommand object ?

thanks gain.

Kelly Ethridge said:
You're missing the closeing brace '}' after then 7 in the VALUES.

Kelly

ramonred said:
Hi All,
this is the error:
Input string was not in a correct format.

this is the code I am trying to debug:
<code>
string sql = @"
INSERT INTO [User]
(UserID, Login, Password, FirstName, LastName,
PhoneNumber, Email, IsAdministrator, Address,
CellNumber, DateOfBirth)
VALUES
('{0}','{1}','{2}','{3}','{4}',
'{5}','{6}','{7',{8},{9},{10})";

//add required values to replace
values.Add(Guid.NewGuid().ToString());
values.Add(txtLogin.Text);
values.Add(txtPwd.Text);
values.Add(txtFName.Text);
values.Add(txtLName.Text);
values.Add(txtPhone.Text);
values.Add(txtEmail.Text);
values.Add(0); //is administrator

//add the optional values or Null
if (txtAddress.Text != string.Empty)
values.Add("'" + txtAddress.Text + "'");
else
values.Add("Null");

if (txtMobile.Text != string.Empty)
values.Add("'" + txtMobile.Text + "'");
else
values.Add("Null");

if (txtBirth.Text != string.Empty)
values.Add("'" + txtBirth.Text + "'");
else
values.Add("Null");

//format the string with the array of values

sql = String.Format(sql, values.ToArray());
</code>
this is the line where that causes the exception:
sql = String.Format(sql, values.ToArray());

I am not asking anyone to debug my code, I only provide it for purposes of
clarification. What I would like to know, is there any easy to see what the
sql string is before it is inserted into the db.

I am a vb programmer newly exposed to the .net world, the method I used to
solve these type of errors was to create a msgbox that had the string once
it waas built, and then I could tell what was causing the problem. What I am
looking for here is something similair.

Thank You.
 

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

Top