Data is not inserted in oracle database from VB6 - oracle

I want to add data in FingerData table in oracle database from VB6 . That is why , I have the following code .
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim cn As String
cn = "Provider=OraOLEDB.Oracle;Password=fingerprintdata;User ID=fingerprintdata;Data Source=10.11.201.84;Persist Security Info=True"
conn.Open cn
cmd.ActiveConnection = conn
conn.CursorLocation = adUseClient
rs.Open "FINGERDATA", conn, adOpenStatic, adLockOptimistic, adCmdTable
s = StrConv(b, vbUnicode)
rs.AddNew
rs!UserName = strName
rs!fingerdata = "123"
rs!key = "Testing 9001"
rs.Update
Set conn = Nothing
Set rs = Nothing
But the data is not inserted . What is the error ? How can I insert data in oracle database from vb6 ?

Please use this statement:
rs.Open "FINGERDATA", conn, adOpenDynamic, adLockOptimistic

Related

Parameterized query in VBScript referring OracleDB

I have a parameterized query which is giving
"ORA-01008: not all variables bound" error.
Dim Conn
Dim Cmd
Dim RS
Dim strID
Dim param
strID = Request.QueryString("id")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open strConnect
Set Cmd = Server.CreateObject("ADODB.Command")
Cmd.CommandText = "SELECT column_name FROM table WHERE (id = :id)"
Set param = Cmd.CreateParameter("id", adVarChar , adParamInput ,50 , strID)
Cmd.Parameters.Append param
Cmd.CommandType = adCmdText
Set Cmd.ActiveConnection = Conn
Set RS = Cmd.Execute()
I'm trying to modify in syntax in several ways, then it is giving
ORA-00936: missing expression
Please help me to get out of this. For your information, there is no problem with connection as i am able to connect with normal query.
a few things to check:
1) try hard coding a value for strID, so instead of:
strID = Request.QueryString("id")
try
strID = 100
2) double check your column definitions and make sure you're selecting from a varchar(50) field
3) make sure you have adovbs.inc referenced on your page for the ADO constants definitions
Thanks #Lankymart, luckily i got solution for this as below. It is working fine for me and sorry for the delay in posting the answer, my issue resolved 2 hours ago.
Dim Conn
Dim Cmd
Dim RS
Dim strID
Dim param
strID = Request.QueryString("id")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open strConnect
Set Cmd = Server.CreateObject("ADODB.Command")
With Cmd
.CommandText = "SELECT column_name FROM table WHERE id = ?"
.Parameters.Append .CreateParameter(,200, 1 ,50 ,strID)
Set .ActiveConnection = Conn
End With
Set RS = Cmd.Execute()

Run-time Error 91: object variable or with block variable not set while linking VB6 and MS access

when i run the given original code the error in below line is shown "Run-time error 91"
con.Open "Provider=Microsoft.Jet.4.0;Data Source=C:\Documents and Settings\XPMUser\Desktop\New Folder\prac1.mdb; Persist Security Info = False"
original code
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub SUBMIT_Click()
con.Open "Provider=Microsoft.Jet.4.0;Data Source=C:\Documents and Settings\XPMUser\Desktop\New Folder\prac1.mdb; Persist Security Info = False"
rs.Open "select DBTB1 from prac1", con, adOpenDynamic, adLockPessimistic
rs.Fields("NUMBER").Value = Text1.Text
rs.Fields("NAME").Value = Text2.Text
rs.Fields("CITY").Value = Text3.Text
MsgBox "data saved!", vbInformation
rs.Update
End Sub
You are getting the Error 91 because you have not actually created the Connection object. Further, you will get the same error with the RecordSet. I have updated your code to allow it to work:
Private Sub SUBMIT_Click()
Set con = New ADODB.Connection
con.Open "Provider=Microsoft.Jet.4.0;Data Source=C:\Documents and Settings\XPMUser\Desktop\New Folder\prac1.mdb; Persist Security Info = False"
Set rs = New ADODB.Recordset
rs.Open "select DBTB1 from prac1", con, adOpenDynamic, adLockPessimistic
rs.AddNew
rs.fields("NUMBER").value = Text1.Text
rs.fields("NAME").value = Text2.Text
rs.fields("CITY").value = Text3.Text
rs.Update
MsgBox "data saved!", vbInformation
End Sub
Also, please note the addition of AddNew prior to updating the database.

VBA Recordset / Oracle and Excel Connect

I've installed tries recordset in my vba statement.
Unfortunately he accesses only the first line in my database. Who can help me?
I'm not very good in VBA it's my first porject. I hope someone can help me with my code. Thank you
Sub Testbox()
Dim conn, Rs
Dim strSQL As String
Dim auswahl As Integer
auswahl = MsgBox("Die Daten werden geladen", vbOKCancel, "Bitte auswählen")
If auswahl = 1 Then
connstring = "UID=user;PWD=passwort;DRIVER={Microsoft ODBC For Oracle};SERVER=server.WORLD;"
Set conn = New ADODB.Connection
With conn
.ConnectionString = connstring
.CursorLocation = adUseClient
.Mode = adModeRead
.Open
End With
Set Rs = CreateObject("ADODB.Recordset")
strSQL = "select * from table where logdatum =1507"
Rs.Open strSQL, conn, 3, 3
Range("A2:A5000") = Rs("scanclient")
Range("B2:B500") = Rs("Sum")
Range("C2:C500") = Rs("batchclass")
Rs.Close
Set Rs = Nothing
conn.Close
Set conn = Nothing
Else
Exit Sub
End If
End Sub
Unfortunately, it is not possible to print data from Recordset into worksheet like that:
Range("A2:A5000") = Rs("scanclient")
Range("B2:B500") = Rs("Sum")
Range("C2:C500") = Rs("batchclass")
You need to replace this code with the below:
Dim i As Long: i = 1
Do Until Rs.EOF
i = i + 1
Cells(i, 1) = Rs("scanclient")
Cells(i, 2) = Rs("Sum")
Cells(i, 3) = Rs("batchclass")
Call Rs.MoveNext
Loop

How to connect a database to crystal report at run time?

I am developing winform application in vb6. I am using crystal report 4.6. I have created a crystal report which shows all data from a table (MS Access). And I unchecked save data with report and i saved the report. I just want to invoke it in application. So I included the component CrystalReportControl in my application. Now i want to set the records to be displayed in the report. The records are selected according to the user input to the text box.
Records are retrived from the database is done in following code.
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Command1_Click()
Set conn = New ADODB.Connection
conn.Open "provider=Microsoft.jet.oledb.4.0;Data Source=" & App.Path &"\faculty.mdb"
Set rs = New ADODB.Recordset
rs.Open "select * from facultydetails where eid=1234", conn, adOpenDynamic, adLockPessimistic
CrystalReport1.ReportFileName = App.Path & "\faculty.rpt"
Set CrystalReport1.DataSource = rs
CrystalReport1.Action = 1
End Sub
Gives an error for the line: Set CrystalReport1.DataSource = rs :
as Property is write-only.
Tell me how the records of the report can be dynamic? Plz help me...
Instead of
Set CrystalReport1.DataSource = rs
do
CrystalReport1.DataSource = rs
EDIT:
Take a look at the following example and see if that will help you:
'CrystalReport1 is the name of the dsr file
Dim Report As New CrystalReport1
Dim cdoRowset As CrystalDataObject.CrystalComObject
Dim varArray() As Variant
'Open ADO Connection
Set m_cnAdo = New ADODB.Connection
m_cnAdo.ConnectionString = "DRIVER={SQL Server};UID=[UserID];PWD=[Password]" _
& ";SERVER=[Server];DATABASE=[Database]"
m_cnAdo.Open
Dim rsAdo As ADODB.Recordset
Dim cmdAdo As ADODB.Command
'Using Embedded Query
Set cmdAdo = New ADODB.Command
Set rsAdo = New ADODB.Recordset
cmdAdo.ActiveConnection = m_cnAdo
cmdAdo.CommandText = "SELECT * FROM Table WHERE Param = " & lngParam1
cmdAdo.CommandType = adCmdText
Set rsAdo = cmdAdo.Execute
Report.Database.SetDataSource rsAdo, 3, 1

Populating VB6 Combo box using Resultset data source

How to Populate VB6 Combo box using Result set data source ... Please Help
Dim con As New ADODB.Connection
Dim rs2 As New ADODB.Recordset
con.Open "Provider = sqloledb;Data Source=Server01;Initial Catalog=Naveen; User ID= ****; password= ****; Integrated Security= True"
rs2.Open "Select * from Customers", con, adOpenDynamic
Do While rs2.EOF <> True
Combo2.AddItem (rs2.Fields(0).Value)
rs2.MoveNext
Loop
I'm not sure if it works the same way as in VB.NET so I would suggest that you look the ADODB.Recordset object and add each item to the combobox.
One way to load data from an Access database into a combo box (change the connection string for a different DB):
Dim oDb As New ADODB.Connection
Dim oRS As New ADODB.Recordset
Dim sSql As String
oDb.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Data\MyAccessDB.mdb;Jet"
sSql = "SELECT DISTINCT([LastName]) FROM [Authors] ORDER BY LastName ASC"
oRS.Open sSql, oDB, adOpenForwardOnly, adLockReadOnly
Do While not oRS.EOF
With cboMyCombo
.AddItem trim$(oRS("LastName").Value)
End With
oRS.MoveNext
Loop
oRS.Close
oDB.Close
Set oRS = Nothing
Set oDB = Nothing

Resources