By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 910 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

Apostrophes in database field

P: n/a
Hi,

I'm doing a database app using MS Access and OleDb adapters, and I'm having
trouble with getting strings containing apostrophes in and out of the
database. I read through a thread below with subject "Apostrophys in text
field - SQL Server as backend" and now I'm trying to figure out how to make
it work in my case, particularly the input from William Ryan.

What I have are a couple fields to be inserted directly as a new row, and
I've been doing this with something like the following (because I'm still
new to this):

INSERT INTO MyTable (Field1, Field2) VALUES ('" & String1 & ", " & String2 &
"')"

String1 and String2 are strings with apostrophes, such as "Bob's Auto Shop."
So I want to do this:

INSERT INTO MyTable (Field1, Field2) VALUES (@String1, @String2)

How do I assign those paramaters before doing the insert? So far I've only
tried:

InsertCmd.Paramaters.Add("@String1", String1)

But I get an error saying @String1 has no default value. The MSDN
documentation is of no help at all--I hardly understand it. I'd appreciate
some help from someone who can speak in layman's terms.

Thanks in advance,
Nathan
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Try replace(string1,"'","''") it will work..

Stan
"Nathan" <nk*********************@softhome.net> a écrit dans le message de
news:OA**************@TK2MSFTNGP12.phx.gbl...
Hi,

I'm doing a database app using MS Access and OleDb adapters, and I'm having trouble with getting strings containing apostrophes in and out of the
database. I read through a thread below with subject "Apostrophys in text
field - SQL Server as backend" and now I'm trying to figure out how to make it work in my case, particularly the input from William Ryan.

What I have are a couple fields to be inserted directly as a new row, and
I've been doing this with something like the following (because I'm still
new to this):

INSERT INTO MyTable (Field1, Field2) VALUES ('" & String1 & ", " & String2 & "')"

String1 and String2 are strings with apostrophes, such as "Bob's Auto Shop." So I want to do this:

INSERT INTO MyTable (Field1, Field2) VALUES (@String1, @String2)

How do I assign those paramaters before doing the insert? So far I've only tried:

InsertCmd.Paramaters.Add("@String1", String1)

But I get an error saying @String1 has no default value. The MSDN
documentation is of no help at all--I hardly understand it. I'd appreciate some help from someone who can speak in layman's terms.

Thanks in advance,
Nathan

Nov 20 '05 #2

P: n/a
Thanks, but I've already figured that out. I would like to know how to
assign paramater values, though. It would make my code a bit cleaner and
hopefully a little faster.

"Stan Sainte-Rose" <st**@cyber972.com> wrote in message
news:ux**************@TK2MSFTNGP10.phx.gbl...
Try replace(string1,"'","''") it will work..

Stan
"Nathan" <nk*********************@softhome.net> a écrit dans le message de
news:OA**************@TK2MSFTNGP12.phx.gbl...
Hi,

I'm doing a database app using MS Access and OleDb adapters, and I'm having
trouble with getting strings containing apostrophes in and out of the
database. I read through a thread below with subject "Apostrophys in text field - SQL Server as backend" and now I'm trying to figure out how to

make
it work in my case, particularly the input from William Ryan.

What I have are a couple fields to be inserted directly as a new row, and I've been doing this with something like the following (because I'm still new to this):

INSERT INTO MyTable (Field1, Field2) VALUES ('" & String1 & ", " &

String2 &
"')"

String1 and String2 are strings with apostrophes, such as "Bob's Auto

Shop."
So I want to do this:

INSERT INTO MyTable (Field1, Field2) VALUES (@String1, @String2)

How do I assign those paramaters before doing the insert? So far I've

only
tried:

InsertCmd.Paramaters.Add("@String1", String1)

But I get an error saying @String1 has no default value. The MSDN
documentation is of no help at all--I hardly understand it. I'd

appreciate
some help from someone who can speak in layman's terms.

Thanks in advance,
Nathan


Nov 20 '05 #3

P: n/a
Cor
Hi Nathan,

For the regulars in the newsgroup

microsoft.public.dotnet.framework.adonet

is this I think a question without to think a single second to answer

Bill (William Ryan who you mention) is mostly active in that newsgroup.

Cor
I'm doing a database app using MS Access and OleDb adapters, and I'm having trouble with getting strings containing apostrophes in and out of the
database. I read through a thread below with subject "Apostrophys in text
field - SQL Server as backend" and now I'm trying to figure out how to make it work in my case, particularly the input from William Ryan.

What I have are a couple fields to be inserted directly as a new row, and
I've been doing this with something like the following (because I'm still
new to this):

INSERT INTO MyTable (Field1, Field2) VALUES ('" & String1 & ", " & String2 & "')"

String1 and String2 are strings with apostrophes, such as "Bob's Auto Shop." So I want to do this:

INSERT INTO MyTable (Field1, Field2) VALUES (@String1, @String2)

How do I assign those paramaters before doing the insert? So far I've only tried:

InsertCmd.Paramaters.Add("@String1", String1)

But I get an error saying @String1 has no default value. The MSDN
documentation is of no help at all--I hardly understand it. I'd appreciate some help from someone who can speak in layman's terms.

Thanks in advance,
Nathan

Nov 20 '05 #4

P: n/a
-----Original Message-----
Thanks, but I've already figured that out. I would like to know how toassign paramater values, though. It would make my code a bit cleaner andhopefully a little faster.


Hello , try this :

Me.SqlCommand1.Parameters.Clear()
With Me.SqlCommand1.Parameters
.Add("@enc", SqlDbType.Char).Value = encomenda
.Add("@obra", SqlDbType.Char).Value = obra
.Add("@pos_enc", SqlDbType.Decimal).Value = pos_enc
End With

Kind Regards
Jorge
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.