SES_Team
asked on
CommandText Property has not been initialized
Dear all,
I m trying to populate a datagridview with data from oracle like below.
Everytime i get the same error : CommandText Property has not been initialized
could anybody tell me what i do wrong here. thanks..
Sub exe_sql()
Try
Dim sql, conn As String
Dim dt As New DataTable
objgrd = New Datagrid
objsql = New SQL
conn = "DATA SOURCE= " & txt_serv.Text & ";user id= " & txt_user.Text & ";password= " & txt_pass.Text & ";"
sql = objsql.txt_sql.Text
Dim oracon As New OracleConnection(conn)
Dim oraadap As New OracleDataAdapter(sql, conn)
With oraadap.SelectCommand
.CommandType = CommandType.Text
.CommandText = sql
.Connection = oracon
End With
oracon.Open()
oraadap.Fill(dt)
Pnl_view.Controls.Clear()
Pnl_view.Controls.Add(objg rd)
objgrd.Dock = DockStyle.Fill
objgrd.grd_outcome.DataSou rce = dt
dt.Clear()
Catch ex As Exception
MessageBox.Show(ex.Message , "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Bu tton2, MessageBoxOptions.DefaultD esktopOnly )
End Try
End Sub
I m trying to populate a datagridview with data from oracle like below.
Everytime i get the same error : CommandText Property has not been initialized
could anybody tell me what i do wrong here. thanks..
Sub exe_sql()
Try
Dim sql, conn As String
Dim dt As New DataTable
objgrd = New Datagrid
objsql = New SQL
conn = "DATA SOURCE= " & txt_serv.Text & ";user id= " & txt_user.Text & ";password= " & txt_pass.Text & ";"
sql = objsql.txt_sql.Text
Dim oracon As New OracleConnection(conn)
Dim oraadap As New OracleDataAdapter(sql, conn)
With oraadap.SelectCommand
.CommandType = CommandType.Text
.CommandText = sql
.Connection = oracon
End With
oracon.Open()
oraadap.Fill(dt)
Pnl_view.Controls.Clear()
Pnl_view.Controls.Add(objg
objgrd.Dock = DockStyle.Fill
objgrd.grd_outcome.DataSou
dt.Clear()
Catch ex As Exception
MessageBox.Show(ex.Message
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sub exe_sql()
Try
Dim sql, conn As String
Dim dt As New DataTable
objgrd = New Datagrid
objsql = New SQL
because everytime it starts with a new objsql it cleares out the text box you fill in after pressing the execute button.
I already found this out myself but since you give the good anwser i will give you the points.
Thanks anyway