473,545 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Input string not in correct format

Hello,

I am having a problem with imputting into a string variable:

Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany,
txtPhone, txtEmail, txtComment, chkGrower, chkProduceDeale r,
txtOtherCustTyp e, chkStandardBags , chkCustomBags,t xtOtherBags) " + _

"VALUES ('" + txtName.Text + "','" + txtCompany.Text + "','" + txtPhone.Text
+ "','" + txtEmail.Text + "','" + txtComment.Text + "','" +
chkGrower.Check ed + "','" + chkProduceDeale r.Checked + _

"','" + txtOtherCustTyp e.Text + "','" + chkStandardBags .Checked + "','" +
chkCustomBags.C hecked + "','" + txtOtherBags.Te xt + "');"
I am running this procedure in a Visual Web Developer Webform. I am kind of
thinking the problem may be the contiuation characters (+ _) on the end of
the second line: If the line wasn't split there it would read,

chkProduceDeale r.Checked + "','" + txtOtherCustTyp e.Text

So I added the underscore next to an existing concatination rather than a
new pair of symbols, + _. I tried breaking the line somewhere else, but
that didn't work.

Thanks for any help.

God Bless,

Mark A. Sam
Mar 24 '06 #1
16 2125
If, as I suspect, the reason for the lines being split with the continuation
character is purely to save you having to scroll sideways to see what you
have written, then my advice is to take the continuation characters out, at
least until you have it working properly.

Have you got Option Strict turned on? I suspect you haven't, otherwise you
would get some compiler errors and/or warnings.

Are the names on the columns in your database table really the same as the
names of the controls name on your form?

Are the datatypes of the database table columns declared as they should be?

What is the value of the resulting string? CLUE: Use Console.Writeli ne to
see it.

In the VALUES clause, I would expect that the value for the chkGrower column
to be either ...,'True',... or ...,'False',... and the same applies to the
other chk... columns, the source of which syuspect to be CheckBoxes.

I would be surprised if the corresponding columns in the database table are
not declared as whatever flavour of boolean that your database engine
supports.

If this is the case then passing the string 'True' or 'False' is your
problem. You need to be passing True or False boolean values.

"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:u9******** ******@TK2MSFTN GP12.phx.gbl...
Hello,

I am having a problem with imputting into a string variable:

Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany,
txtPhone, txtEmail, txtComment, chkGrower, chkProduceDeale r,
txtOtherCustTyp e, chkStandardBags , chkCustomBags,t xtOtherBags) " + _

"VALUES ('" + txtName.Text + "','" + txtCompany.Text + "','" +
txtPhone.Text + "','" + txtEmail.Text + "','" + txtComment.Text + "','" +
chkGrower.Check ed + "','" + chkProduceDeale r.Checked + _

"','" + txtOtherCustTyp e.Text + "','" + chkStandardBags .Checked + "','" +
chkCustomBags.C hecked + "','" + txtOtherBags.Te xt + "');"
I am running this procedure in a Visual Web Developer Webform. I am kind
of thinking the problem may be the contiuation characters (+ _) on the end
of the second line: If the line wasn't split there it would read,

chkProduceDeale r.Checked + "','" + txtOtherCustTyp e.Text

So I added the underscore next to an existing concatination rather than a
new pair of symbols, + _. I tried breaking the line somewhere else, but
that didn't work.

Thanks for any help.

God Bless,

Mark A. Sam

Mar 24 '06 #2
Hello Stephany,

I thought about that after I posted this, so I ran it as one single line and
still have the issue.

Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany,
txtPhone, txtEmail, txtComment, chkGrower, chkProduceDeale r,
txtOtherCustTyp e, chkStandardBags , chkCustomBags,t xtOtherBags) VALUES ('" +
txtName.Text + "','" + txtCompany.Text + "','" + txtPhone.Text + "','" +
txtEmail.Text + "','" + txtComment.Text + "','" + chkGrower.Check ed + "','"
+ chkProduceDeale r.Checked + "','" + txtOtherCustTyp e.Text + "','" +
chkStandardBags .Checked + "','" + chkCustomBags.C hecked + "','" +
txtOtherBags.Te xt + "');"

I don't see the problem. This format worked fine when I tested it with the
first two field, txtName and txtCompany. I don't see any syntax errors,
though they could be there.

Another question if I may. Should I remove the single quote surrouding the
boolean fields, like

+ "','" + chkStandardBags .Checked + "','" +

Thank you.

Mark
Mar 24 '06 #3
PL


You shouldnt concatenate your queries in the first palce since a bunch of
security issues arise with this method and it is also not very readable
code. Instead use what the framework provides you with and parameterize your
query and send in the values with the datatypes properly defined, for
example:

I'm using C# here since that is what I'm used to but the same applies to
VB.NET, I have also shortened your query just for this example:

string strSQL= "INSERT INTO tblContactForm1 (txtName, txtCompany) VALUES
(@txtName, @txtCompany)";

SqlConnection objconn = new SqlConnection(s ConnStr);
objconn.Open();

SqlCommand objcommand = new SqlCommand(strS QL,objconn);

// Set the parameter values
objcommand.Para meters.Add("(@t xtName", SqlDbType.VarCh ar).Value =
txtName.Text;
objcommand.Para meters.Add("(@t xtCompany", SqlDbType.VarCh ar).Value =
txtCompany.Text ;

// ... rest of code

PL.
Mar 24 '06 #4
Another point, as you are using VB.NET I STRONGLY recommend that you use the
String concatenation operator (&) instead of (+). The (+) operator for
string concatenation is a legacy from very old versions of BASIC and use of
it, especially with Option Strict Off, can lead to very nasty and difficult
to find problems. E,g: You might expect "1" + "2" to yield "21" but it will,
most likely yield 3.

It still appears that you haven't tyurned Option Strict On, otherwise the
code you just posted wouldn't have compiled.

Did you dump the reult of the concatenation? If so, what is it?

It would have worked perfectly when you tested it with the first two fields
(txtName and txtCompany) because, I suspect, the corresponding database
colums are of the 'text' or similar type.

Removing the single quotes surrouding the boolean fields may do the trick,
depending on what the database engine expects for boolean values.

If you do remove them then your code should look like:

... & "'," & chkStandardBags .Checked.ToStri ng & ",'" & ...

The fragment you posted still has the single quotes in it.
"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:uH******** ******@tk2msftn gp13.phx.gbl...
Hello Stephany,

I thought about that after I posted this, so I ran it as one single line
and still have the issue.

Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany,
txtPhone, txtEmail, txtComment, chkGrower, chkProduceDeale r,
txtOtherCustTyp e, chkStandardBags , chkCustomBags,t xtOtherBags) VALUES ('"
+ txtName.Text + "','" + txtCompany.Text + "','" + txtPhone.Text + "','" +
txtEmail.Text + "','" + txtComment.Text + "','" + chkGrower.Check ed +
"','" + chkProduceDeale r.Checked + "','" + txtOtherCustTyp e.Text + "','" +
chkStandardBags .Checked + "','" + chkCustomBags.C hecked + "','" +
txtOtherBags.Te xt + "');"

I don't see the problem. This format worked fine when I tested it with
the first two field, txtName and txtCompany. I don't see any syntax
errors, though they could be there.

Another question if I may. Should I remove the single quote surrouding
the boolean fields, like

+ "','" + chkStandardBags .Checked + "','" +

Thank you.

Mark

Mar 24 '06 #5
Mark,

Just try parameters, it seems more work, however you will see that as soon
as you are used to them, don't want to do it in another way anymore.

Have a look at our website for this simple sample.

http://www.vb-tips.com/default.aspx?...a-ae802ee71c86

I hope this helps,

Cor

"Mark A. Sam" <ms**@Plan-It-Earth.Net> schreef in bericht
news:uH******** ******@tk2msftn gp13.phx.gbl...
Hello Stephany,

I thought about that after I posted this, so I ran it as one single line
and still have the issue.

Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany,
txtPhone, txtEmail, txtComment, chkGrower, chkProduceDeale r,
txtOtherCustTyp e, chkStandardBags , chkCustomBags,t xtOtherBags) VALUES ('"
+ txtName.Text + "','" + txtCompany.Text + "','" + txtPhone.Text + "','" +
txtEmail.Text + "','" + txtComment.Text + "','" + chkGrower.Check ed +
"','" + chkProduceDeale r.Checked + "','" + txtOtherCustTyp e.Text + "','" +
chkStandardBags .Checked + "','" + chkCustomBags.C hecked + "','" +
txtOtherBags.Te xt + "');"

I don't see the problem. This format worked fine when I tested it with
the first two field, txtName and txtCompany. I don't see any syntax
errors, though they could be there.

Another question if I may. Should I remove the single quote surrouding
the boolean fields, like

+ "','" + chkStandardBags .Checked + "','" +

Thank you.

Mark

Mar 24 '06 #6
Stephany,

I was writing to you that it was C# because of that semicolon at the end.

Now I see that it is extra good. It start with a DIM.

:-)

Cor

"Stephany Young" <noone@localhos t> schreef in bericht
news:ek******** ********@TK2MSF TNGP09.phx.gbl. ..
Another point, as you are using VB.NET I STRONGLY recommend that you use
the String concatenation operator (&) instead of (+). The (+) operator for
string concatenation is a legacy from very old versions of BASIC and use
of it, especially with Option Strict Off, can lead to very nasty and
difficult to find problems. E,g: You might expect "1" + "2" to yield "21"
but it will, most likely yield 3.

It still appears that you haven't tyurned Option Strict On, otherwise the
code you just posted wouldn't have compiled.

Did you dump the reult of the concatenation? If so, what is it?

It would have worked perfectly when you tested it with the first two
fields (txtName and txtCompany) because, I suspect, the corresponding
database colums are of the 'text' or similar type.

Removing the single quotes surrouding the boolean fields may do the trick,
depending on what the database engine expects for boolean values.

If you do remove them then your code should look like:

... & "'," & chkStandardBags .Checked.ToStri ng & ",'" & ...

The fragment you posted still has the single quotes in it.
"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:uH******** ******@tk2msftn gp13.phx.gbl...
Hello Stephany,

I thought about that after I posted this, so I ran it as one single line
and still have the issue.

Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany,
txtPhone, txtEmail, txtComment, chkGrower, chkProduceDeale r,
txtOtherCustTyp e, chkStandardBags , chkCustomBags,t xtOtherBags) VALUES ('"
+ txtName.Text + "','" + txtCompany.Text + "','" + txtPhone.Text + "','"
+ txtEmail.Text + "','" + txtComment.Text + "','" + chkGrower.Check ed +
"','" + chkProduceDeale r.Checked + "','" + txtOtherCustTyp e.Text + "','"
+ chkStandardBags .Checked + "','" + chkCustomBags.C hecked + "','" +
txtOtherBags.Te xt + "');"

I don't see the problem. This format worked fine when I tested it with
the first two field, txtName and txtCompany. I don't see any syntax
errors, though they could be there.

Another question if I may. Should I remove the single quote surrouding
the boolean fields, like

+ "','" + chkStandardBags .Checked + "','" +

Thank you.

Mark


Mar 24 '06 #7
Hiya Cor - How's things?

I suspect that the semi-colon (in the concatenated string) indicates that he
is using a Jet database. Young players often think it is needed because
Access automatically appends a semi-colon to the query when you have a look
at a querydef in SQL view in Access.

Before we get him on to a SqlCommand or OleDbCommand oobject with parameter,
I'm trying to get him to understand what the actual probelm is and how he is
causing it.

Regards.
"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:uo******** ******@tk2msftn gp13.phx.gbl...
Stephany,

I was writing to you that it was C# because of that semicolon at the end.

Now I see that it is extra good. It start with a DIM.

:-)

Cor

"Stephany Young" <noone@localhos t> schreef in bericht
news:ek******** ********@TK2MSF TNGP09.phx.gbl. ..
Another point, as you are using VB.NET I STRONGLY recommend that you use
the String concatenation operator (&) instead of (+). The (+) operator
for string concatenation is a legacy from very old versions of BASIC and
use of it, especially with Option Strict Off, can lead to very nasty and
difficult to find problems. E,g: You might expect "1" + "2" to yield "21"
but it will, most likely yield 3.

It still appears that you haven't tyurned Option Strict On, otherwise the
code you just posted wouldn't have compiled.

Did you dump the reult of the concatenation? If so, what is it?

It would have worked perfectly when you tested it with the first two
fields (txtName and txtCompany) because, I suspect, the corresponding
database colums are of the 'text' or similar type.

Removing the single quotes surrouding the boolean fields may do the
trick, depending on what the database engine expects for boolean values.

If you do remove them then your code should look like:

... & "'," & chkStandardBags .Checked.ToStri ng & ",'" & ...

The fragment you posted still has the single quotes in it.
"Mark A. Sam" <ms**@Plan-It-Earth.Net> wrote in message
news:uH******** ******@tk2msftn gp13.phx.gbl...
Hello Stephany,

I thought about that after I posted this, so I ran it as one single line
and still have the issue.

Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName,
txtCompany, txtPhone, txtEmail, txtComment, chkGrower, chkProduceDeale r,
txtOtherCustTyp e, chkStandardBags , chkCustomBags,t xtOtherBags) VALUES
('" + txtName.Text + "','" + txtCompany.Text + "','" + txtPhone.Text +
"','" + txtEmail.Text + "','" + txtComment.Text + "','" +
chkGrower.Check ed + "','" + chkProduceDeale r.Checked + "','" +
txtOtherCustTyp e.Text + "','" + chkStandardBags .Checked + "','" +
chkCustomBags.C hecked + "','" + txtOtherBags.Te xt + "');"

I don't see the problem. This format worked fine when I tested it with
the first two field, txtName and txtCompany. I don't see any syntax
errors, though they could be there.

Another question if I may. Should I remove the single quote surrouding
the boolean fields, like

+ "','" + chkStandardBags .Checked + "','" +

Thank you.

Mark



Mar 24 '06 #8
Agree with the group that you should use parameters but I also suggest that
you perform some sort of assertion that your values will actually fit into
the DB fields you are tryinh to populate, you will see this error if they
overrun.

"Cor Ligthert [MVP]" <no************ @planet.nl> wrote in message
news:Os******** ******@TK2MSFTN GP12.phx.gbl...
Mark,

Just try parameters, it seems more work, however you will see that as soon
as you are used to them, don't want to do it in another way anymore.

Have a look at our website for this simple sample.

http://www.vb-tips.com/default.aspx?...a-ae802ee71c86

I hope this helps,

Cor

"Mark A. Sam" <ms**@Plan-It-Earth.Net> schreef in bericht
news:uH******** ******@tk2msftn gp13.phx.gbl...
Hello Stephany,

I thought about that after I posted this, so I ran it as one single line
and still have the issue.

Dim strSQL As String = "INSERT INTO tblContactForm1 (txtName, txtCompany,
txtPhone, txtEmail, txtComment, chkGrower, chkProduceDeale r,
txtOtherCustTyp e, chkStandardBags , chkCustomBags,t xtOtherBags) VALUES ('"
+ txtName.Text + "','" + txtCompany.Text + "','" + txtPhone.Text + "','"
+ txtEmail.Text + "','" + txtComment.Text + "','" + chkGrower.Check ed +
"','" + chkProduceDeale r.Checked + "','" + txtOtherCustTyp e.Text + "','"
+ chkStandardBags .Checked + "','" + chkCustomBags.C hecked + "','" +
txtOtherBags.Te xt + "');"

I don't see the problem. This format worked fine when I tested it with
the first two field, txtName and txtCompany. I don't see any syntax
errors, though they could be there.

Another question if I may. Should I remove the single quote surrouding
the boolean fields, like

+ "','" + chkStandardBags .Checked + "','" +

Thank you.

Mark


Mar 24 '06 #9

"Stephany Young" <noone@localhos t> wrote in message
news:ek******** ********@TK2MSF TNGP09.phx.gbl. ..
Another point, as you are using VB.NET I STRONGLY recommend that you use
the String concatenation operator (&) instead of (+). The (+) operator for
string concatenation is a legacy from very old versions of BASIC and use
of it, especially with Option Strict Off, can lead to very nasty and
difficult to find problems. E,g: You might expect "1" + "2" to yield "21"
but it will, most likely yield 3.

Actually I started using the & but thought that in VB it was standard to use
the +. I'll go back to the &.

It still appears that you haven't tyurned Option Strict On, otherwise the
code you just posted wouldn't have compiled.
I didn't know that. I don't understand that term or what it is for. Why
wouldn't I want the code to be compiled?


Did you dump the reult of the concatenation? If so, what is it?
I don't know what you mean. I'm new to .Net.

It would have worked perfectly when you tested it with the first two
fields (txtName and txtCompany) because, I suspect, the corresponding
database colums are of the 'text' or similar type.
Yes, and the chk box controls correspond to Access Yes/No fields. Could
that be a problem?

Removing the single quotes surrouding the boolean fields may do the trick,
depending on what the database engine expects for boolean values.
I tried it, and it didn't help, but it really should have an effect since I
am not writing to the DB at this point, only assigning the string variable.

If you do remove them then your code should look like:

... & "'," & chkStandardBags .Checked.ToStri ng & ",'" & ...

The fragment you posted still has the single quotes in it.


I know, I put them back in after I tested this and before I posted.
God Bless,

Mark
Mar 24 '06 #10

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

Similar topics

2
21075
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 execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. ...
0
768
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 error and where it originated in the code. Exception Details: System.FormatException: Input string was not in a correct format. Source Error: ...
5
2503
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 not in the correct format. Input string was not in a correct format. Description: An unhandled exception occurred during the execution of the...
1
1835
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
2840
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 = request.QueryString("enddate") Line 20: Line 21: if cint(eventid) = "0" then
0
2535
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 stack trace for more information about the error and where it originated in the code. Exception Details: System.FormatException: Input string was...
0
11954
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 form controls so
0
3157
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 consists of a label control(hidden when run in browser). Also an Sql data source control connected to database tables for a photo album. Also label web...
1
4510
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 Photoadmin/default.aspx i got the following message and info. Input string was not in a correct format. Description: An unhandled exception occurred...
1
4741
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 THE PROGRAM PLEASE HELP ME Server Error in '/WebApplication1' Application....
0
7802
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7410
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7746
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5962
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4941
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3438
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1010
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
693
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.