|
|
|
สอบถามปัญหาการ insert ข้อมูลเข้า MS sql ในรูปประโยคที่มี 's มันadd ไม่เข้าระบบครับผม |
|
|
|
|
|
|
|
เปลี่ยนไปใช้แบบ Parameters ครับ
Code (C#)
System.Data.SqlClient.SqlConnection objConn;
System.Data.SqlClient.SqlCommand objCmd;
String strConnString,strSQL;
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
objConn = new System.Data.SqlClient.SqlConnection(strConnString);
objConn.Open();
//*** FOR INSERT ***//
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " +
"VALUES (@sCustomerID,@sName,@sEmail,@sCountryCode,@sBudget,@sUsed)";
objCmd = new System.Data.SqlClient.SqlCommand(strSQL,objConn);
//*** Sample 1 ***//
/*
objCmd.Parameters.AddWithValue("@sCustomerID","C005");
objCmd.Parameters.AddWithValue("@sName","Weerachai Nukitram");
objCmd.Parameters.AddWithValue("@sEmail","[email protected]");
objCmd.Parameters.AddWithValue("@sCountryCode","TH");
objCmd.Parameters.AddWithValue("@sBudget","2000000");
objCmd.Parameters.AddWithValue("@sUsed","1000000");
*/
//*** Sample 2 ***//
objCmd.Parameters.Add(new SqlParameter("@sCustomerID","C005"));
objCmd.Parameters.Add(new SqlParameter("@sName","Weerachai Nukitram"));
objCmd.Parameters.Add(new SqlParameter("@sEmail","[email protected]"));
objCmd.Parameters.Add(new SqlParameter("@sCountryCode","TH"));
objCmd.Parameters.Add(new SqlParameter("@sBudget","2000000"));
objCmd.Parameters.Add(new SqlParameter("@sUsed","1000000"));
objCmd.ExecuteNonQuery();
(C#) ASP.NET System.Data.SqlClient - Parameter Query (SqlParameter)
|
|
|
|
|
Date :
2016-12-01 11:35:03 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แทนที่ ' ด้วย '' ครับ
|
|
|
|
|
Date :
2016-12-01 13:35:13 |
By :
fonfire |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณครับผม
|
|
|
|
|
Date :
2016-12-02 10:07:21 |
By :
yatard |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2016-12-06 09:32:07 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|