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.
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.