can someone look at this?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How can i get this work going against an Oracle Table? I have it working with SQL, but when I change my db to Oracle I get an error.

The where clause is based on what is selected in the drop down box.



objConn = New OracleConnection(dbConn)
objConn.Open()
strSQL = "Select car, model from autos where car= @cars"
objDataAdapter = New OracleDataAdapter(strSQL, objConn)
'this is the error line
myCommand.Parameters.Add(New OracleParameter("@cars", OracleDbType.NVarchar2, ParameterDirection.Input))

myCommand.Parameters("@cars").Value = ddSport.SelectedValue

objDataAdapter.Fill(ds)
dgGames.DataSource = ds
dgGames.DataBind()

the error i get is
Object reference not set to an instance of an object on line 79

thanks
 
What is 'myCommand'? Most likely it has not been instantiated - there is
certainly no code to instantiate it here.

IGotYourDotNet said:
How can i get this work going against an Oracle Table? I have it working
with SQL, but when I change my db to Oracle I get an error.
The where clause is based on what is selected in the drop down box.



objConn = New OracleConnection(dbConn)
objConn.Open()
strSQL = "Select car, model from autos where car= @cars"
objDataAdapter = New OracleDataAdapter(strSQL, objConn)
'this is the error line
myCommand.Parameters.Add(New OracleParameter("@cars",
OracleDbType.NVarchar2, ParameterDirection.Input))
 
(untested)

Dim objConn As New OracleConnection(dbConn)

Dim strSQL As String = "Select car, model from autos where car=
@cars"

Dim myCommand As New OracleCommand(strSQL, objConn)
myCommand.Parameters.Add(New OracleParameter("@cars",
OracleType.NVarChar, 2)).Value = ddSport.SelectedValue

Dim objDataAdapter As New OracleDataAdapter(myCommand)

objDataAdapter.Fill(ds)
dgGames.DataSource = ds
dgGames.DataBind()


HTH,
Greg


IGotYourDotNet said:
How can i get this work going against an Oracle Table? I have it working
with SQL, but when I change my db to Oracle I get an error.
The where clause is based on what is selected in the drop down box.



objConn = New OracleConnection(dbConn)
objConn.Open()
strSQL = "Select car, model from autos where car= @cars"
objDataAdapter = New OracleDataAdapter(strSQL, objConn)
'this is the error line
myCommand.Parameters.Add(New OracleParameter("@cars",
OracleDbType.NVarchar2, ParameterDirection.Input))
 
Yes, it should be:
Dim myCommand As New OracleCommand

Your code never instantiated an objec t- you only declared the variable.

NullReferenceException is always very specific to you using a variable that
has not been instantiated. That is the only time it occurs - so when it
does, check the line number and make sure that you instantiate every object
you are using.
 
Your command object has never been initiated.

Also, if you look at your code, you will see that the dataadapter is not
"tied" to the command object in anyway.

Try it this way...

Dim myCommand As New OracleCommand(strSQL, objConn)
myCommand.Parameters.Add(New OracleParameter("@cars",
OracleType.NVarChar, 2)).Value = ddSport.SelectedValue '<--- not sure about
type or size, not sure how to use NVarChar2 (and how many characters is
that, obviously not just 2 like I have here)

Dim objDataAdapter As New OracleDataAdapter(myCommand)

objDataAdapter.Fill(ds)

PS: As you can probably tell, I don't know crap about Oracle. :^) I can't
seem to import the namespace your are using. Specificly the
Oracle.DataAccess.Client.OracleDBType. Are you using the .NET provider from
MS, or one from Oracle (I assume they have their own).

Greg
 
I don't know, a wild guess... you never istantiated your ds variable either?
:^)

Dim ds As New DataSet

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top