Dim rs As New ADODB.Recordset
strConnectionString = "Provider=SQLOLEDB.1;Integrated Security=True;Initial Catalog=Hospital_ABC;Data Source=ITEM-47791\SQLEXPRESS;Persyst Security Info=False;Command Properties='Command Time Out=45'"
Set connexion = New ADODB.Connection
connexion.ConnectionString = strConnectionString
connexion.ConnectionTimeout = 30
connexion.Open strConnectionString
rs.Open "insert into student_info(name,rollNo,age, class,address,assigned_teacher)values('name',rollno,age,'cls','add','assteac')", connexion
i am using this code to insert value inn my table ,,,but i got error as--run time error( multiple step OLEDB operation generated error, check each OLEDB status value, if available)
please check it what wrong in thos code .....
Look at this:
http://support.microsoft.com/kb/269495
It says:
The following are two possible causes
of this error:
In the registry, under the key for an OLE DB provider's CLSID, there may
be an entry named OLEDB_SERVICES. If
the OLE DB provider that is used to
make the ADO connection does not have
the OLEDB_SERVICES entry, and ADO
tries to set up a property that is not
supported by the provider, the error
occurs. For more information about
this registry entry, see the
"Resolution" section.
If OLEDB_SERVICES entry exists but there is a problem in the ADO
connection string, the error occurs.
Do not use this in connection string
Persyst Security Info=False;Command Properties='Command Time Out=45'
try this:
rs.Open "insert into student_info(name,rollNo,age,class,address,assigned_teacher) values('n',1,1,'c','a','a')", connexion
For me, the error usually happens when a data is too long for the field. You can further troubleshoot this by updating one field at a time to find the one that is broken (Update name, then update name and number, then name and number and age, etc).
Related
Updating an old VB6 app using ADO and disconnected recordsets. Works just fine except there are some old ADODC objects I'm also updating to use disconnected recordsets. I've written code to insert new records and return the new ID value which is great.
However, when I try to update the current new record (in the recordset via .AddNew), I get "Multiple-step operation generated errors. Check each status value."
I can update other columns just fine. Just not the SQL identity column in the recordset. All I want is for subsequent references to that column to now have the correct information.
The searches on that error seem to indicate that it's possible to update the value, but I've tried CVar(newID), just newID and nothing seems to work.
The Recordset is set as
.CursorType = adOpenStatic
.CursorLocation = adUseClient
.LockType = adLockOptimistic
I could hack each instance to somehow reload the entire recordset with the new object, but that seems like a lot of workaround. In most cases, the newid never gets used until it's reloaded. But I'm trying to replicate the action of a connected ADODC which would save the record and refresh itself with the new id.
Any options?
This question is a continuation of question 37339682: Connecting Excel VBA to oracle DB using 'ODBC'
In the above question, there is a step by step guide to connect Excel to ODBC. (Oracle database) I have successful connected to the Oracle database and retrieve a table.
My questions are:
(1) How to write Excel VBA code, such that it can read SQL query from a cell, and return the SQL query result in a table. I guess I need to setup a "database object" in the Excel VBA code.
(2) If such code are to be performed in Microsoft Access. How different would it be?
Not a database object but a recordset object
Sub Example
Dim rs as New Recordset 'the new is important
Dim Conn as New Connection
Conn.connectionstring = "whatever"
'see here https://www.connectionstrings.com/microsoft-odbc-for-oracle/
Conn.open
Dim sql as string
sql = "whatever" 'could be text in cell ie sql = range("g1").text
rs.open sql,conn
if not rs.eof then 'if there's any data then
Activesheet.range("a2").copyfromrecordset rs 'puts data into cell
End If
rs.close
conn.close
end sub
Currently I am working on a project that forces me to use Vb6 as a front end and Oracle 9i as a backend in my application. I need to retrieve data from a table in oracle, and display it in a VB6 form. Im using a recordset for this, but for some reason it doesnt contain any record even when a valid record is present in the table in question. Can anyone tell me what's wrong? Any help would be appreciated. My code is as follows-
Private Sub Command1_Click()
Dim sql As String
Set rs = New ADODB.Recordset
sql = "select test23.phoname from test23 where test23.ops='" + Text1.Text + "'"
rs.Open sql, con, adOpenStatic, adLockOptimistic
If rs.EOF = False Then
Form7.Show
Form7.Label2.Caption = rs.Fields("phoname")
End If
End Sub
The if statements never execute, as the recordset always seems empty. If I remove the EOF condition I get a runtime error 3021. Is there something wrong with my sql query? The table test23 is already present in my oracle database with attributes serialno, phoname and ops.
Thanks-
Ron
I have struggled through this myself some years ago. The problem could be in several areas: specificaly the connection, the Oracle drivers, the Oracle home or the query itself.
I would strongly recommend that you download the free version of TOAD which will allow you to test both your connection (I assume ODBC of some sort) and you can then execute the query manually using TOAD.
Are you getting any exceptions?
Hopefully from this you can then correct your code/connection/query.
Good luck
I would also point out that adoOpenStatic and adoLockOptimistic are mutually exclusive property values, as optimistic locking only applies to updatable recordsets and static recordsets aren't updatable (except in batch mode with adoLockBatchOptimistic). This may be confusing the Oracle OLEDB provider somehow.
I want to assign database table columns to recordset in vb6. And i want update them with the values that i have in my another recordset. Is that possible?
How to assign the data from table to recordset?
An ADODB recordset is not a mirror of a database table. The recordset contains whatever you want it to based on the query you provide it. So to load the data from the database into the recordset you need to execute a query. This can be done in two ways.
Use the ADODB.Connection.Execute method and set your recordset to the result.
Dim con as New ADODB.Connection
Dim rs as ADODB.Recordset
con.ConnectionString = "some connection string"
con.Open
Set rs = con.Execute("SELECT * FROM table")
Create an ADODB.Recordset object, specify the connection and then call the Open method passing it a query.
Dim con as New ADODB.Connection
Dim rs as New ADODB.Recordset
con.ConnectionString = "some connection string"
con.Open
Set rs.ActiveConnection = con
rs.Open "SELECT * FROM table"
The query can be as simple or complex as you want it be. The query could ask for fields from multiple tables and the recordset will still contain the results of the query, however you won't be able to tell which table the fields are from.
A fabricated ADODB Recordset object is a fine container object because it has some great methods built in: Filter, Sort, GetRows, GetString, Clone, etc plus support for paging, serializing as XML, etc. For details see "Adding Fields to a Recordset" in this MSDN article.
But if you are working with database data, why not just execute a query?
I'm trying to connect to an Oracle Database with Access 2003.
I want to use an ODBC connection and I want to set it up so that the user doesn't need to enter a password.
One of the problems I am having though is my sql query uses INTERFACE.Products and Access sees the period and thinks I'm trying to opening a file. IE Interface.MDB, when thats a part of my sql query.
Option Compare Database
Function OracleConnect() As Boolean
Dim ws As Workspace
Dim db As Database
Dim LConnect As String
Dim myQuery As String
Dim myRS As Recordset
On Error GoTo Err_Execute
LConnect = "ODBC;DSN=Oracle;UID=user;PWD=password;"
'Point to the current workspace
Set ws = DBEngine.Workspaces(0)
'Connect to Oracle
Set db = ws.OpenDatabase("", False, True, LConnect)
myQuery = "Select * from INTERFACE.Products"
Set rst = db.OpenRecordset(myQuery)
rst.Close
db.Close
Exit Function
Err_Execute:
MsgBox MsgBox("Error Number: " & Err.Number & " Message: " & Err.Description)
End Function
Could you try something like:
Set rst = db.OpenRecordset(mQuery, dbOpenSnapshot, dbSQLPassThrough)
This would just send the query verbatim to the Oracle database.
In the Access documentation for OpenRecordset you'll find this note:
If you open a Recordset in a Microsoft Access workspace and you don't specify a type, OpenRecordset creates a table-type Recordset.
This may be the source of the error you're getting.
As a rule, I would suggest to always be explicit in your parameters to OpenRecordset: the default behaviour isn't always consistent and it can generate strange errors.
I'm not sure about your design, but one way to make things a bit easier for you may be to simply create linked tables in Access.
In that case, you would be able to write queries against your INTERFACE.Products Oracle table as if if were a local Products table.
It would also save you from having to manage the connections yourself.
The recordset you are creating must use a query written with Access SQL. The table must be an Access table (a table defined in the mdb). It can be a local table or linked table. An Access table cannot have a "." (dot) in its name. If you were to link the Oracle table INTERFACE.Products in Access it would be INTERFACE_Products (Access will replace illegal characters in the remote database table name with "_") unless you renamed it in Access. Thus your query should be "Select * from INTERFACE_Products"
It is possible to create a recordset using Oracle SQL, but that must be created with a Pass-Through query.