Apostrophes in database field

N

Nathan

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
 
N

Nathan

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

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
 
J

Jorge

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top