Results 1 to 5 of 5

Thread: CommandText not initialized?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    CommandText not initialized?

    Hi there,

    I am trying to get data back from SQL but i always get this error. What does it mean and how do I sort it?

    CommandText property has not been initialized



    Code:
    Dim SQLCommand As New SqlClient.SqlCommand
            Dim sqlconn As New SqlClient.SqlConnection(ConnectionString)
    
    
            sqlconn.Open()
            SQLCommand.Connection = sqlconn
    
            Dim SQLDataAdapter As New SqlClient.SqlDataAdapter
            SQLDataAdapter.SelectCommand = New SqlClient.SqlCommand(query, sqlconn)
    
            Dim SQLDataSet As New DataSet
    
            SQLDataAdapter.Fill(SQLDataSet)
    
            Dim SQLConnection As New SqlClient.SqlCommand(query, sqlconn)
            'we have the query ready in a string
    
    
            SQLCommand.ExecuteNonQuery()

    after that has been solved...I would also like to know how do i display the results on the screen? (im using asp.net btw....)

    Thanks

  2. #2
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    [list=1]
    VB Code:
    1. [*]Dim SQLCommand As New SqlClient.SqlCommand[*]Dim sqlconn As New SqlClient.SqlConnection(ConnectionString)[*]Dim SQLDataAdapter As New SqlClient.SqlDataAdapter[*] SQLDataAdapter.SelectCommand = New SqlClient.SqlCommand(query, sqlconn)[*]Dim SQLDataSet As New DataSet[*]SQLDataAdapter.Fill(SQLDataSet)[*]Dim SQLConnection As New SqlClient.SqlCommand(query, sqlconn)[*]SQLCommand.ExecuteNonQuery()
    [/list=1]

    DataAdapter objects are just a series of sqlCommand objects... so I suspect your Select command on your DataAdapter is flunked. Try running the wizard again, or inspecting the Wizard-generated code in the Designer section.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    thanks, seems to work now

    another Q is - displaying the data.

    I am using a datalist now (new at all of this btw) and in order to display the records, some of the fields do not exist in the SQL table database but have been joined from other tables/fields etc... - the code was not done by me.

    so how do i tell it in the datalistview to display that type of data? because if i do:

    ..['mts.media_type']"

    it chucks an error

    but if a field is there in that table like owner then it will work

    any ideas?

    is there a better way of viewing the results on the page?

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I'm guessing the dataset (or a table of that dataset) you are binding to does not contain these extra fields correct?

    What I would need to know is where the other fields are coming from: Are they coming from a DataTable you have created...read from file... etc...

    For many operations, you can begin by executing the DataSet Merge method on whatever data container you are trying to incorporate... as illustrated in the following MSDN reference:
    http://msdn.microsoft.com/library/de...mergetopic.asp

    For other operations, you may need to systematically loop through the corresponding rows in the two sources, and build a new one by using for-loop and adding new rows to a new datatable.

    In any case, the MSDN reference should be a start. Without further details, it is hard to suggest the proper method of attacking the data.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773
    thanks figured out the problem earlier

    just took out everything before the . and works! hehe

    another quick q if i may:

    is there a way i can sort the data recieved from sql in the datalist? so for example i may have a header with either a link or button, when clicked it sorts that field? i guess its fairly simple isnt it?

    put a button on top of each column

    when clicked, do the same query build again but order by that field?

    if i wanted to put the results in a text box rather than a label, would that be the exact same? except change the label to a text box? or would i have to do something else?

    thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width