การค้นหาหรือสร้าง query กับค่าที่มี ' (apostrophe) ปนอยู่ด้วย
กระทู้เก่าบอร์ด อ.สุภาพ ไชยา

 253   1
URL.หัวข้อ / URL
การค้นหาหรือสร้าง query กับค่าที่มี ' (apostrophe) ปนอยู่ด้วย

วันนี้ผมไปที่ 
http://www.thai.net/accesshotline 
แล้วเจอคำถามข้อที่ 30 
http://freeboard.ptcsweb.com/view_q.php?ruser=accesshotline&wbid=30 
 
โดยมีเนื้อหาของคำถามดังนี้ 
 
Dim strSurname As String  
Dim strSQL As String  
Dim rsTbl As DAO.Recordset  
 
strSurname = CmbSurname  
 
 
'Sql statement  
strSQL = "select * from [Person] WHERE surname like '" & strSurname & "';"  
 
มีปัญหาเรื่อง SQL ค่ะ คือถ้าหากว่า string ของ strSurname เป็น O'Conell หรือ ตัวอื่นๆ ที่มี ' อยู่ จะมีวิธีการแก้อย่างไรค่ะ เพื่อให้สามารถหาข้อมูลได้ ขอบคุณล่วงหน้า สาธุๆๆๆๆมีคนมาตอบเร็วๆด้วยเถอะ จะส่งงานพรุ่งนี้อยู่แล้วเพิ่งเจอปัญหาอ่ะ  
 
ไอซ์ [ วันอาทิตย์ ที่ 16 มิถุนายน 2545 เวลา 13:29 น. ]    
 
 
ผมได้ตอบไปดังนี้ครับ 
 
 
จะต้องใช้ * เข้าช่วยด้วย ถ้าต้องการที่จะค้นแบบ Wildcard  
 
ดังนี้  
strSQL = "select * from [Person] WHERE surname like ""*"" & """ & strSurname & """ & ""*"";"  
  
 
และเมื่อ 2-3 วันที่ผ่านผม มีคำถามคล้ายๆ กันนี้ที่ถามไว้ที่ 
http://board.quicktechusa.com/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=1;t=001065 
 
เนื้อหาของคำถามมีดังนี้ครับ 
 
I am trying to do a find with an apostrophe in the name in a field called community. The find is working as long as there isn't an apostrophe in the name. I am getting a syntex error Missing Operator when I do a find with the apostrophe (Ex. St. John's)  
 
The code I am using is  
 
Me.RecordsetClone.FindFirst "community= '" & UCase (strcommunity) & "'" 
 
and 
 
Me.RecordsetClone.FindFirst "[Community] = '" & Me![cbocommunity] & "'"  
 
 
ผมได้ตอบไปดังนี้ครับ 
 
 
Try 3 " before the combo and 4 " after the combo. 
 
Me.RecordsetClone.FindFirst "[Community] = """ & Me![cbocommunity] & """"  
 
ให้ใส่ " 3 ตัวก่อน และ " 4 ตัว หลังค่าที่ได้จาก Combo Box 

1 Reply in this Topic. Dispaly 1 pages and you are on page number 1

1 @R06521
   
@ ประกาศใช้งานเว็บบอร์ดใหม่ => บอร์ดเรียนรู้ Access สำหรับคนไทย
แล้วจะใส่ลิ้งอ้างอิงมาที่โพสต์เก่านี้หรือไม่ก็ตามสะดวกครับ
Time: 0.0530s