Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help With Oracle Select Into Statement 3

Status
Not open for further replies.

chilly442

Technical User
Jun 25, 2008
151
US
I need to grab three values from a table and store them into variables. I have tried a few variation of the following but am not getting what I need.
Code:
 Try
            Con.Open()
            Dim sql As New StringBuilder(1024)
            Dim objcmd As New OdbcCommand(sql.ToString, Con)
            sql.Append("SELECT EFOR, EAF, PEA INTO MyEFOR, MyEAF, MyPEA FROM History WHERE Unit = ('" & UnitText & "')")
            objcmd = New OdbcCommand(sql.ToString, Con)
            Value = objcmd.ExecuteScalar()
            Con.Close()
        Catch ex As Exception
            MsgResult = MsgBox("Unable to connect. " & ex.Message)
End Try

Any suggestions?
Is what I am trying to do the correct way of doing this?

Thanks,
Chilly442
 
Did the catch display an error?
If so what was the error?

Thanks,
SMBrown
 
I am getting an error.
ORA-00905: missing keyword.

I think that the syntax is off, but am not sure what it is supposed to look like.

Thanks,
Chilly442
 
Anyone out there?

Still no luck. I know that the line:
Value = objcmd.ExecuteScalar()
is not correct. I am not looking for only one value. I need to pull and store three values.

Any help is worth a star, even if it is not the solution!

Thanks,
Chilly442
 

Are you set on "Select ... INTO..." approach only?

Could you just do Select and populate a table and read the values this way?

Just an idea.....

Have fun.

---- Andy
 
How about using a DataReader?
Code:
        Using cn As New OdbcConnection(My.Settings.[red]YourConnectionString[/red]), cm As New OdbcCommand(String.Empty, cn)
            cn.Open()

            cm.CommandText = "SELECT EFOR, EAF, PEA FROM History WHERE Unit = '" & UnitText & "'"

            Dim rd As OdbcDataReader = cm.ExecuteReader(CommandBehavior.SingleRow)
            If (rd.Read) Then
                MyEFOR = rd.GetString(0)
                MyEAF = rd.GetString(1)
                MyPEA = rd.GetString(2)
            End If
            rd.Close()

        End Using
 
That is what I was looking for.

Thanks again to both of you. I always end up with what I need one way or another.

Thanks,
Chilly442
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top