Use INSERT INTO (field1,field2 ...) VALUES (' Val1 ', ' val2 ' ...) , an error occurs if there is a single quotation mark in the value.
Processing method: Determine whether the Val1,val2 contains single quotation marks, if the single quotation marks, then the single quotation mark ' replaced with two single quotation marks '.
Organize fields and field values into a hashtable, and then abstract a function getsqlbyhashtable () that organizes SQL statements:
HashTable HT =new HashTable ();
Ht.add (FIELD1,VAL1);
Ht.add (FIELD2,VAL2);
Ht.add (FIELD3,VAL3);
。。。
public string getsqlbyhashtable (string tablename,hashtable ht) {
StringBuilder sb=new StringBuilder ();
Sb.append ("INSERT INTO" +tablename+ "(");
StringBuilder fsb=new StringBuilder ();
StringBuilder vsb=new StringBuilder ();
foreach (Var key in Ht. Keys)
{
Fsb.append (key+ ",");
String Value=ht[key];
if (value.trim () = = "")
{
Value= "";
}
Else
{
if (value. Contains ("'"))
{
Value=value.replace ("'", "" ");
}
Value= "'" +value+ "'";
}
Vsb.append (value+ ",");
}
Sb.append (Fsb.tostring (). Substring (0,fsb.tostring (). length-1));
Sb.append (") VALUES (");
Sb.append (Vsb.tostring (). Substring (0,vsb.tostring (). length-1));
Sb.append (")");
return sb.tostring ();
}
When Oracle inserts string data, there is a ' single quote ' in the string