开发者

Insert using ADO with classic ASP

' Setting variables
 Dim con, sql_insert, data_source

 data_source = "project_db"
 sql_insert = "insert into cart ( UserID,Count,ProductName,ProductDescription,ProductPrice) values ('"&user_id&"','"&count&"','开发者_高级运维"&product_name&"','"&product_description&"','"&product_price&"')"

 ' Creating the Connection Object and opening the database
 Set con = Server.CreateObject("ADODB.Connection")
 con.Open data_source

 ' Executing the sql insertion code
 con.Execute sql_insert

 ' Done. Now Close the connection
 con.Close
 Set con = Nothing

AS you can see , it is a simple code . and it worked in my local host for 5 or 6 times. but now it didn't work. What's the problem ? I think , it's about my database or memory. i setup 2 different iis in 2 different computer and they behave same... please help..

Thanks


Does it give you any error message? Make sure all the values you are inserting actually have values and are not blank or null. You can check this by response.write all the values and then response.end to see if they contain any values.


I bet it's a data-dependent error. You should be using ADO parameters. Those will ensure that extraneous SQL-unfriendly characters in your input do not adversely affect your database operation. You should also use them to guard against SQL injection issues.

Some docs are available at http://msdn.microsoft.com/en-us/library/ms675869(VS.85).aspx, and you can google for "ADO parameters" and find many relevant examples.


I believe that 'data_source' should be focused on (and agreed with Tom Gullen as regards to error messages. Always use Option Explicit at the top of your pages).

con.Open either expects some DSN parameters or a database connection string to be passed within 'data_source'.

Examples, respectively :

data_source = DSN_Database, DSN_User, DSN_Password 

(these 'DSN_' parameters are found/set in your DSN configuration)

OR :

data_source = "Driver={SQL Server};Server=server.domain.com;Database=project_db;uid=MyUser;pwd=MyPass;""
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜