Oracle connection-passing input to query!!
I am having a problem with oracle 10g and vb2005 express.
I can connect. But I am trying to do a select statement with a condition where the variable value is read from a text box.
It cannot understand that the variable value needs to be read from the box. Now the same works in access and sql server so the question is HOW DO YOU PASS A PARAMETER TO A QUERY THAT WILL BE UNDERSTOOD BY VB2005?
I am getting an ORA-01008 all variables are not bound message.
Code below:
Dim ocon As New OracleConnection(cstring)
Dim sql As String = "insert into dept values (@deptno,'@dname','@loc')"
Dim sqlb As String = "select deptno,dname,loc from dept where deptno=&deptno" Dim rfs As Integer
ocon.Open()
MsgBox("Database is open")
Dim objcommand As New OracleCommand(sqlb, ocon)
objcommand.Parameters.Add("&deptno", Data.OracleClient.OracleType.Char, 10, tbox1.Text)
Dim objdataadapter As New OracleDataAdapter(objcommand)
Dim objdatatable As New Data.DataTable("dept")
objdataadapter.Fill(objdatatable)
Dim objdatarow As DataRow
ListBox1.Items.Clear()
For Each objdatarow In objdatatable.Rows
ListBox1.Items.Add(objdatarow("deptno"))
Next
If ListBox1.Items.Count > 0 Then
MsgBox("There is already an entry")
ListBox1.Items.Clear()
tbox1.Clear()
ocon.Close()
Else
Dim objcommandb As New OracleCommand(sql, ocon)
objcommandb.Parameters.Add("@deptno", OracleType.VarChar, 10).Value = tbox1.Text
objcommandb.Parameters.Add("@dname", OracleType.VarChar, 10).Value = tbox2.Text
objcommandb.Parameters.Add("@loc", OracleType.VarChar, 10).Value = tbox3.Text
Dim objdataadapterb As New OracleDataAdapter(objcommandb)
rfs = objcommandb.ExecuteNonQuery
objdataadapterb.Dispose()
objdataadapterb = Nothing
objcommandb.Dispose()
objcommandb = Nothing
End If
MsgBox("Database is now closed")
ocon.Close()
|