• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1593
  • Last Modified:

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
0
SES_Team
Asked:
SES_Team
1 Solution
 
REA_ANDREWCommented:
this line

.CommandText = sql

and this line

sql = objsql.txt_sql.Text

make sure that sql is not null before you get into .CommandText = sql as it would appear that it is.  You need to set the variable sql with some commandtext like an SQL select statement or Stored procedure name.  With any necessary mods

Andrew
0
 
SES_TeamAuthor Commented:
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
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now