|
-
Jun 24th, 2004, 11:56 AM
#1
Thread Starter
Frenzied Member
single quotes in SQL statement
if i have a value that has to be insterted into a field in Access but the value has a single quote, ie. Example's. if i write the instert statement the following way would it work?
VB Code:
dim sql as string = "insert into THETABLE (THEFIELD) values(" & """example's""" & ")"
-
Jun 24th, 2004, 11:59 AM
#2
Frenzied Member
I usually do replaces on all my SQL statements that don't use parameters just in case.
Replace(strSQL,"'","''") that is one single quote with two single quotes.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jun 24th, 2004, 12:41 PM
#3
Frenzied Member
-
Jun 24th, 2004, 04:40 PM
#4
-
Jun 25th, 2004, 06:20 AM
#5
Thread Starter
Frenzied Member
thanx Redth...did the trick....still learning or converting over to the .NET side of things...thanx again
-
Jun 28th, 2004, 03:28 PM
#6
Frenzied Member
That was an INSERT statement. How do you do it when it's a SELECT statement? For example,...
Code:
SELECT * FROM tbl_One WHERE Field = 'userdatehere';
The SQL statement is passed into a SqlDataAdapter when created, so you can't use the SqlCommand object. So how do you use SqlParameter method with a SELECT statement?
~Peter

-
Jun 28th, 2004, 04:37 PM
#7
Lively Member
Guys guys,
when you use SQl server, OLEDB objects are irrelevant.
This is the perfect code for adding parameters (assuming that you previously declared SqlConnection(Conn) and SqlDataAdapter(DAdap) objects, in order to use these references you MUST import the System.Data.SqlClient Class):
VB Code:
DAdap.InserCommand = New SqlCommand("insert into THETABLE (THEFIELD) values (@Val)", Conn)
Dim Prm as SqlParameter = DAdap.InsertCommand.Parameters.Add(New SqlParameter("@Val", SqlDbType.Char))
Prm.SourceColumn = "THEFIELD"
Prm.SourceVersion = DataRowVersion.Current
Do you think my life is easy?
Do you think it's good to win?
do you think it's nice to kill?
Do you think learning is a must?
Do you think computers are nothing?
Do you think this post is stupid?
Do ypu think we're really humen?
DO YOU THINK IT'S GOOD TO THINK AT ALL? ? ? ! ! !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|