473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Input string was not in a correct format.

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.

Nov 16 '05 #1
5 9432
You're missing the closeing brace '}' after then 7 in the VALUES.

Kelly

"ramonred" <ra******@discussions.microsoft.com> wrote in message news:62**********************************@microsof t.com...
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.

Nov 16 '05 #2
<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" wrote:
You're missing the closeing brace '}' after then 7 in the VALUES.

Kelly

"ramonred" <ra******@discussions.microsoft.com> wrote in message news:62**********************************@microsof t.com...
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.


Nov 16 '05 #3
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" <ra******@discussions.microsoft.com> wrote in message news:F5**********************************@microsof t.com...
<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" wrote:
You're missing the closeing brace '}' after then 7 in the VALUES.

Kelly

"ramonred" <ra******@discussions.microsoft.com> wrote in message news:62**********************************@microsof t.com...
> 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.
>


Nov 16 '05 #4
As a side issue, you are not handling the possibility of apostrophes in (for
example) the LastName field. Everything will work great until the first
O'Malley or D'Artagnan comes along.

You are also vulnerable to SQL injection attacks.

For these and performance reasons, use parameterized queries.

Best,

--Bob

"ramonred" <ra******@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
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})";

Nov 16 '05 #5
Thank you both for your very helpful responses.

"Bob Grommes" wrote:
As a side issue, you are not handling the possibility of apostrophes in (for
example) the LastName field. Everything will work great until the first
O'Malley or D'Artagnan comes along.

You are also vulnerable to SQL injection attacks.

For these and performance reasons, use parameterized queries.

Best,

--Bob

"ramonred" <ra******@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
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})";


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim | last post by:
im using asp.net, C# to enter data into a table in sql server...however im getting this error: Input string was not in a correct format. Description: An unhandled exception occurred during the...
0
by: lianfe_ravago | last post by:
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...
5
by: blackg | last post by:
Input string not in correct format -------------------------------------------------------------------------------- I am trying to view a picture from a table. I am getting this error Input string...
1
by: amitbadgi | last post by:
Welcome back amitbadgi | Logout | Faq Knowledge Discovery Keys COMPUTER PROGRAMMING, DATA MINING, STATISTICS, ARTIFICIAL INTELLIGENCE * Settings * Photos * Lists * MVPs * Forums * Blogs
1
by: amitbadgi | last post by:
I am gettign this error, while migration an app to asp.net Exception Details: System.FormatException: Input string was not in a correct format. Source Error: Line 19: Dim enddate =...
0
by: hudhuhandhu | last post by:
have got an error which says Input string was not in a correct format. as follows.. Description: An unhandled exception occurred during the execution of the current web request. Please review the...
0
by: Anonieko | last post by:
Are there any javascript codes there? Answer: Yes On the PageLoad event call InitialClientControsl as follows /// <summary> /// This will add client-side event handlers for most of the...
0
by: sehguh | last post by:
Hiya Folks, I am Currently using windows xp. Also using Visual Web Developer 2005 and Microsoft Sql server 2005. The main page consists of an aspx page and a master page. The page also...
1
by: sehguh | last post by:
Hello folks I have recently been studying a book called "sams teach yourself asp.net 2.0 in24 hours by scott mitchell. I have reached page 614 but when i tried to run an asp page called...
1
by: differentsri | last post by:
THIS IS AN ASP.NET 1.1 APPLICATION IAM TRYING TO UPDATE THE FIELD BUT I AM NOT ABLE TO UPDATE IT? CAN U TELL THE REASON ? IT IS GIVING THE FOLLOWING ERROR BELOW I HAVE ALSO GIVEN THE CODE OF...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.