Link to home
Start Free TrialLog in
Avatar of SES_Team
SES_TeamFlag for Thailand

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(objgrd)
            objgrd.Dock = DockStyle.Fill
            objgrd.grd_outcome.DataSource = dt

            dt.Clear()

        Catch ex As Exception
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly)
        End Try

    End Sub
ASKER CERTIFIED SOLUTION
Avatar of REA_ANDREW
REA_ANDREW
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SES_Team

ASKER

Andrew you're right. I made a little mistake at this part:

   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