473,385 Members | 1,942 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,385 software developers and data experts.

Problem with Insert Statement...

Hello there,

This is my SQL Insert Statement to insert a single into a table on a
database;

INSERT tb_test VALUES(' & _
txtTest1.Text & "' " & _
txtTest2.Text & "' " & _
txtPrice.Text & "')"

Now when I execute this code against the data provider I got and error
saying that I should use the Convert Function on the column "Price", because
of course, the Price on the SQL MSDE is of money type.

I have tried this to try to convert from varchar to money, but no luck.
Dim us As New CultureInfo("en-US")
CType((txtPrice.Text), Decimal).ToString("c", us)

Anybody out there to guide me or give a hint on how to solve this issue?

Thanks very much for your help on this one.

Manny
Nov 20 '05 #1
6 1039
Manuel,

You need to use a SQLCommand class and not build the strings this way to
avoid all sorts of issues.

And when creating SQLParameters to add to that command class you can set the
dbtype to money and it will work fine.

HTH

Shane
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:gW2Cc.14599$mm3.5892@clgrps13...
Hello there,

This is my SQL Insert Statement to insert a single into a table on a
database;

INSERT tb_test VALUES(' & _
txtTest1.Text & "' " & _
txtTest2.Text & "' " & _
txtPrice.Text & "')"

Now when I execute this code against the data provider I got and error
saying that I should use the Convert Function on the column "Price", because of course, the Price on the SQL MSDE is of money type.

I have tried this to try to convert from varchar to money, but no luck.
Dim us As New CultureInfo("en-US")
CType((txtPrice.Text), Decimal).ToString("c", us)

Anybody out there to guide me or give a hint on how to solve this issue?

Thanks very much for your help on this one.

Manny

Nov 20 '05 #2
Hi there, Thanks for replying to my post.

I am using a SQLCommand this is the complete code;
strSQL = "INSERT tb_product VALUES ('" & _
txtServiceCode.Text & "', '" & _

txtServiceName.Text & "', '" & _

txtPrice.Text & "')"

cnSQL = New SqlConnection(ConnectionString)

cnSQL.Open()

cmSQL = New SqlCommand(strSQL, cnSQL)

cmSQL.ExecuteNonQuery()

It fails right on the last line here.

When you say that SQLparameters are better to accomplish this, could you
extend on that?

Thanks for your help on this one,

Manny.

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Manuel,

You need to use a SQLCommand class and not build the strings this way to
avoid all sorts of issues.

And when creating SQLParameters to add to that command class you can set the dbtype to money and it will work fine.

HTH

Shane
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:gW2Cc.14599$mm3.5892@clgrps13...
Hello there,

This is my SQL Insert Statement to insert a single into a table on a
database;

INSERT tb_test VALUES(' & _
txtTest1.Text & "' " & _
txtTest2.Text & "' " & _
txtPrice.Text & "')"

Now when I execute this code against the data provider I got and error
saying that I should use the Convert Function on the column "Price",

because
of course, the Price on the SQL MSDE is of money type.

I have tried this to try to convert from varchar to money, but no luck.
Dim us As New CultureInfo("en-US")
CType((txtPrice.Text), Decimal).ToString("c", us)

Anybody out there to guide me or give a hint on how to solve this issue?

Thanks very much for your help on this one.

Manny


Nov 20 '05 #3
Hi Manuel,

Have a look at this and look than as well somewhere further to the different
contstructions of the parameters.

http://msdn.microsoft.com/library/de...mmandtopic.asp

On this pages they are more difficult than strictly needed.

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps?

Cor
Hi there, Thanks for replying to my post.

I am using a SQLCommand this is the complete code;
strSQL = "INSERT tb_product VALUES ('" & _
txtServiceCode.Text & "', '" & _

txtServiceName.Text & "', '" & _

txtPrice.Text & "')"

cnSQL = New SqlConnection(ConnectionString)

cnSQL.Open()

cmSQL = New SqlCommand(strSQL, cnSQL)

cmSQL.ExecuteNonQuery()

It fails right on the last line here.

When you say that SQLparameters are better to accomplish this, could you
extend on that?

Thanks for your help on this one,

Manny.

Nov 20 '05 #4
Well set the commandstring to
"INSERT tb_produce VALUES(@Servicecode,@ServiceName,@Price)
the @Price is symbolic that this is a parameter.
after you craete
Dim cmdSQL As New System.Data.SqlClient.SqlCommand(strSQL, cnSQL)
Add parameters like so... (I will show the one for price since it has money
type... you must do the other also)
Dim p As New System.Data.SqlClient.SqlParameter("@Price", txtPrice.Text)
p.DbType = System.Data.SqlDbType.Money
s.Parameters.Add(p)

now your command object will have the parameters, their values and types and
you should have no problems, don't have to worry about user string
containnig ' or injected SQL commands.

HTH,

Shane
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:ee7Cc.1532$933.10@clgrps12...
Hi there, Thanks for replying to my post.

I am using a SQLCommand this is the complete code;
strSQL = "INSERT tb_product VALUES ('" & _
txtServiceCode.Text & "', '" & _

txtServiceName.Text & "', '" & _

txtPrice.Text & "')"

cnSQL = New SqlConnection(ConnectionString)

cnSQL.Open()

cmSQL = New SqlCommand(strSQL, cnSQL)

cmSQL.ExecuteNonQuery()

It fails right on the last line here.

When you say that SQLparameters are better to accomplish this, could you
extend on that?

Thanks for your help on this one,

Manny.

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Manuel,

You need to use a SQLCommand class and not build the strings this way to
avoid all sorts of issues.

And when creating SQLParameters to add to that command class you can set

the
dbtype to money and it will work fine.

HTH

Shane
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:gW2Cc.14599$mm3.5892@clgrps13...
Hello there,

This is my SQL Insert Statement to insert a single into a table on a
database;

INSERT tb_test VALUES(' & _
txtTest1.Text & "' " & _
txtTest2.Text & "' " & _
txtPrice.Text & "')"

Now when I execute this code against the data provider I got and error
saying that I should use the Convert Function on the column "Price",

because
of course, the Price on the SQL MSDE is of money type.

I have tried this to try to convert from varchar to money, but no luck. Dim us As New CultureInfo("en-US")
CType((txtPrice.Text), Decimal).ToString("c", us)

Anybody out there to guide me or give a hint on how to solve this issue?
Thanks very much for your help on this one.

Manny



Nov 20 '05 #5
Thanks a bunch Shane for your help.

Manny.

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:Oh****************@TK2MSFTNGP12.phx.gbl...
Well set the commandstring to
"INSERT tb_produce VALUES(@Servicecode,@ServiceName,@Price)
the @Price is symbolic that this is a parameter.
after you craete
Dim cmdSQL As New System.Data.SqlClient.SqlCommand(strSQL, cnSQL)
Add parameters like so... (I will show the one for price since it has money type... you must do the other also)
Dim p As New System.Data.SqlClient.SqlParameter("@Price", txtPrice.Text)
p.DbType = System.Data.SqlDbType.Money
s.Parameters.Add(p)

now your command object will have the parameters, their values and types and you should have no problems, don't have to worry about user string
containnig ' or injected SQL commands.

HTH,

Shane
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:ee7Cc.1532$933.10@clgrps12...
Hi there, Thanks for replying to my post.

I am using a SQLCommand this is the complete code;
strSQL = "INSERT tb_product VALUES ('" & _
txtServiceCode.Text & "', '" & _

txtServiceName.Text & "', '" & _

txtPrice.Text & "')"

cnSQL = New SqlConnection(ConnectionString)

cnSQL.Open()

cmSQL = New SqlCommand(strSQL, cnSQL)

cmSQL.ExecuteNonQuery()

It fails right on the last line here.

When you say that SQLparameters are better to accomplish this, could you
extend on that?

Thanks for your help on this one,

Manny.

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:u0**************@TK2MSFTNGP10.phx.gbl...
Manuel,

You need to use a SQLCommand class and not build the strings this way to avoid all sorts of issues.

And when creating SQLParameters to add to that command class you can set
the
dbtype to money and it will work fine.

HTH

Shane
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:gW2Cc.14599$mm3.5892@clgrps13...
> Hello there,
>
> This is my SQL Insert Statement to insert a single into a table on a
> database;
>
> INSERT tb_test VALUES(' & _
> txtTest1.Text & "' " & _
> txtTest2.Text & "' " & _
> txtPrice.Text & "')"
>
> Now when I execute this code against the data provider I got and

error > saying that I should use the Convert Function on the column "Price",
because
> of course, the Price on the SQL MSDE is of money type.
>
> I have tried this to try to convert from varchar to money, but no

luck. > Dim us As New CultureInfo("en-US")
> CType((txtPrice.Text), Decimal).ToString("c", us)
>
> Anybody out there to guide me or give a hint on how to solve this issue? >
> Thanks very much for your help on this one.
>
> Manny
>
>



Nov 20 '05 #6
No problem.
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:dknCc.17247$mm3.7794@clgrps13...
Thanks a bunch Shane for your help.

Manny.

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:Oh****************@TK2MSFTNGP12.phx.gbl...
Well set the commandstring to
"INSERT tb_produce VALUES(@Servicecode,@ServiceName,@Price)
the @Price is symbolic that this is a parameter.
after you craete
Dim cmdSQL As New System.Data.SqlClient.SqlCommand(strSQL, cnSQL)
Add parameters like so... (I will show the one for price since it has money
type... you must do the other also)
Dim p As New System.Data.SqlClient.SqlParameter("@Price", txtPrice.Text)
p.DbType = System.Data.SqlDbType.Money
s.Parameters.Add(p)

now your command object will have the parameters, their values and types

and
you should have no problems, don't have to worry about user string
containnig ' or injected SQL commands.

HTH,

Shane
"Manuel Canas" <mc*****@hotmail.com> wrote in message
news:ee7Cc.1532$933.10@clgrps12...
Hi there, Thanks for replying to my post.

I am using a SQLCommand this is the complete code;
strSQL = "INSERT tb_product VALUES ('" & _
txtServiceCode.Text & "', '" & _

txtServiceName.Text & "', '" & _

txtPrice.Text & "')"

cnSQL = New SqlConnection(ConnectionString)

cnSQL.Open()

cmSQL = New SqlCommand(strSQL, cnSQL)

cmSQL.ExecuteNonQuery()

It fails right on the last line here.

When you say that SQLparameters are better to accomplish this, could you extend on that?

Thanks for your help on this one,

Manny.

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message news:u0**************@TK2MSFTNGP10.phx.gbl...
> Manuel,
>
> You need to use a SQLCommand class and not build the strings this way to
> avoid all sorts of issues.
>
> And when creating SQLParameters to add to that command class you can set the
> dbtype to money and it will work fine.
>
> HTH
>
> Shane
>
>
> "Manuel Canas" <mc*****@hotmail.com> wrote in message
> news:gW2Cc.14599$mm3.5892@clgrps13...
> > Hello there,
> >
> > This is my SQL Insert Statement to insert a single into a table on
a > > database;
> >
> > INSERT tb_test VALUES(' & _
> > txtTest1.Text & "' " & _
> > txtTest2.Text & "' " & _
> > txtPrice.Text & "')"
> >
> > Now when I execute this code against the data provider I got and

error > > saying that I should use the Convert Function on the column "Price", > because
> > of course, the Price on the SQL MSDE is of money type.
> >
> > I have tried this to try to convert from varchar to money, but no

luck.
> > Dim us As New CultureInfo("en-US")
> > CType((txtPrice.Text), Decimal).ToString("c", us)
> >
> > Anybody out there to guide me or give a hint on how to solve this

issue?
> >
> > Thanks very much for your help on this one.
> >
> > Manny
> >
> >
>
>



Nov 20 '05 #7

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

Similar topics

3
by: Jason Callas | last post by:
I have a stored procedure that runs as a step in a scheduled job. For some reason the job does not seem to finish when ran from the job but does fine when run from a window in SQL Query. I know...
5
by: Ritesh | last post by:
Hi All, According to my observation using SP_WHO2 in my database, some INSERT statements are getting blocked by SELECT statements. Though the blocking SELECT statement is having ReadPast hint,...
4
by: Dani | last post by:
Hi everyone Description of the problem: Using a PreparedStatement to write down an integer (int) plus a timestamp for testing purposes. When read out again the integer looks very different. We...
4
by: Bradley Burton | last post by:
I'm using Allen Brown's code for audit logging (http://allenbrowne.com/AppAudit.html), but I'm having a problem. My aud table doesn't populate with the tracking info at all. I think it might be a...
3
by: alexmaster_2004 | last post by:
hi i have made an application using C# that access sql2000. this application is just used to insert data to the database. i use something like this in my code: // string colmnA = TextBox1.Text;...
9
by: Jack | last post by:
Hi, I am gathering the input values to a form using Request.form method from the processing page. After all the data is captured, I am building sql statement out of it. Using a response.write...
2
by: mob1012 via DBMonster.com | last post by:
Hi All, I wrote last week about a trigger problem I was having. I want a trigger to produce a unique id to be used as a primary key for my table. I used the advice I received, but the trigger is...
22
by: b_r | last post by:
Hi, I'm trying to make a simple operation (insert into DB) in VB 2005 and SQL Server. The code is as follows: Dim sConnectionString As String = _ "Data...
8
by: Red | last post by:
If auto-format is turned off in VS2008, there is apparently no way to indent a line. Under Tools->Options->Text Editor->C#->Formatting, there are three checkboxes. Unchecking those seems to cause...
1
by: Maklar60 | last post by:
I am attempting to execute an INSERT statement on my page but continually get the following error: Microsoft OLE DB Provider for ODBC Drivers error '80040e14' Incorrect syntax near '<'. ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.