CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2310|Reply: 4

Prob dgn string yg ada --> '

[Copy link]
Post time 11-7-2007 05:36 PM | Show all posts |Read mode
Sya develope sistem gun ASP.Net, VB.Net. Cth:

Dim SQL as String
Dim OLEConn As New System.Data.Odbc.OdbcConnection
Dim OLESql As New System.Data.Odbc.OdbcCommand

SQL="Insert Into a_vendor Values (.........)"
OLESql.CommandText = SQL
OLESql.Connection = OLEConn
OLESql.ExecuteReader()



MASALAH/ERROR:
-Prob apabila ada string yg ada tanda '
-Cth: Che' Mat


Harap dpt membantu.....TQ

Rate

1

View Rating Log

Reply

Use magic Report


ADVERTISEMENT


Post time 11-7-2007 07:30 PM | Show all posts

Reply #1 aks_berhad's post

DBMS anggap apostrophe tu sebagai special character untuk menandakan bermula dan tamatnya variable jenis String. Jadi string che' mat dikerat tinggal che sahaja sbb dbms anggap apostrophe tu tanda penutup string che dan dbms tak tau apa nak buat dengan bakinya, so error.

manual mysql mencadangkan:
When writing application programs, any string that might contain any of these special characters must be properly escaped before the string is used as a data value in an SQL statement that is sent to the MySQL server.


Proses dulu string che' mat untuk handle special character seperti single quote tu seperti menambah satu lagi single quote atau backslash sebelum apostrophe tu. Ada juga rujukan yang mencadangkan supaya guna parameterized stored procedure. Dalam contoh ko, jadikan sql statement ko tu dalam bentuk stored procedure, che' mat tu dimasukkan ke dalam object sqlparameter yang akan automatic handle special characters dan feed sqlparameter tu ke dalam stored procedure.

Rujukan:
1.  http://dev.mysql.com/doc/refman/5.0/en/string-syntax.html
2. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbcode/html/vbtskcodecallingparameterizedstoredprocedurevisualbasic.asp

[ Last edited by  alusmetai at 11-7-2007 08:48 PM ]

Rate

1

View Rating Log

Reply

Use magic Report

 Author| Post time 12-7-2007 12:02 AM | Show all posts
Alusmetai,

Terima kasih bebanyak...sya cuba buat store prosedure tuh tp cam payah sikit. So sya guna ASCII Character.
Sila click di sini ---> http://yorktown.cbe.wwu.edu/sandvig/docs/ASCIICodes.aspx

Alhamdulillah ia berjaya...
Reply

Use magic Report

 Author| Post time 11-4-2008 09:31 PM | Show all posts
Nak update solution.
Baru2 nih ada prob ngan cara ASCII nie.
Saya dah cuba carik solution laen.
Tambah lagi satu...

Cth:

Dato' --> jadik : Dato''


Sekian..............
Reply

Use magic Report

Post time 12-4-2008 01:44 PM | Show all posts

Reply #4 aks_berhad's post

sebenarnye itu ajer cara senang nak elakkan masalah pasal tanda apotrophy tue

tiap kali dapat string buat string.replace ("'" , "''")  harap dapat nampak..

Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT


Forum Hot Topic

 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

8-1-2025 12:31 PM GMT+8 , Processed in 0.080328 second(s), 23 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list