smus Posted May 26, 2017 Share Posted May 26, 2017 How to add some data to DB using "Insert into" query. I now use AddNew and Update with "Select from": Dim adoCon, strCon, sco, SQLStatement Set adoCon = Server.CreateObject("ADODB.Connection") SQLStatement = "SELECT * FROM table" sco.Open SQLStatement, adoCon, 3, 3 sco.AddNew "string", info sco.Update But I need 'Insert into' to be executed Link to comment Share on other sites More sharing options...
justsomeguy Posted May 26, 2017 Share Posted May 26, 2017 What is the sco object? Link to comment Share on other sites More sharing options...
dlbHome Posted May 27, 2017 Share Posted May 27, 2017 I use this... <code> l = "INSERT INTO TABLE (fldUserName,fieldwhatever) VALUES ('" & strUserName & "','" & strwhatever & "')" con.Execute(l) </code> Link to comment Share on other sites More sharing options...
smus Posted May 31, 2017 Author Share Posted May 31, 2017 Cannot add even with addNew method: one of the variables is not added to the table, while others are inserted Link to comment Share on other sites More sharing options...
smus Posted May 31, 2017 Author Share Posted May 31, 2017 (edited) sco.Open SQLStatement, adoCon, 3, 3 What do 3, 3 numbers mean in this expression? Edited May 31, 2017 by smus Link to comment Share on other sites More sharing options...
justsomeguy Posted May 31, 2017 Share Posted May 31, 2017 You'll have to look up the documentation on the Open method, which will require you to figure out what kind of object sco is in the first place. That was my first question. Link to comment Share on other sites More sharing options...
smus Posted June 28, 2017 Author Share Posted June 28, 2017 I don't know, the code worked well with this object, but it looks like it is not needed in this context Link to comment Share on other sites More sharing options...
justsomeguy Posted June 28, 2017 Share Posted June 28, 2017 SQLStatement, adoCon, 3, and 3 are the parameters that are being sent to the open method. It is impossible to know what those are without figuring out what kind of object sco is and looking up the documentation for the open method to see what it expects. Link to comment Share on other sites More sharing options...
smus Posted July 5, 2017 Author Share Posted July 5, 2017 On 28.06.2017 at 11:10 PM, justsomeguy said: SQLStatement, adoCon, 3, and 3 are the parameters that are being sent to the open method. It is impossible to know what those are without figuring out what kind of object sco is and looking up the documentation for the open method to see what it expects. You are right, it is difficult to define it without the context. I took this sample code from one of the tutorials and adjusted it for my simple needs. Now as we can see from the code below there are double object creations there. I am also not sure why there is the second RecordSet creation here: Dim adoCon, strCon, sco, SQLStatement Set adoCon = Server.CreateObject("ADODB.Connection") strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\wwwroot\msaccess.mdb;" 'Set the connection string to the database adoCon.connectionstring = strCon 'Set an active connection to the Connection object adoCon.Open 'Initialise the main ADO recordset object Set sco = Server.CreateObject("ADODB.Recordset") This code was initially previous to the code I copied at the beginning of this topic. Link to comment Share on other sites More sharing options...
justsomeguy Posted July 5, 2017 Share Posted July 5, 2017 If sco is an ADO recordset object, you can look at the documentation for open here to figure out what the parameters are used for: https://docs.microsoft.com/en-us/sql/ado/reference/ado-api/open-method-ado-recordset You can click through to see the various options for the cursor and lock types. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now