Results 1 to 6 of 6

Thread: Object reference not set to an instance of an object

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    83

    Object reference not set to an instance of an object

    Hi:

    i get this message quite often. below is part of the code which gives the error. can u find anything wrong?

    Dim ac, desc As String

    ac = e.Item.Cells(0).Text
    desc = e.Item.Cells(1).Text

    Dim sqlselect As String
    Dim conn1 As New OleDb.OleDbConnection("Provider=MSDAORA.1;Password=eas;User ID=eas;Data Source=WETST920.world")

    sqlselect = "select * from subarea where upper (code) ='" & UCase(ac) & "' "

    Dim del As New OleDb.OleDbCommand(sqlselect, conn1)
    conn1.Open()
    del.ExecuteNonQuery()
    conn1.Close()

    dscmd.SelectCommand.CommandText = sqlselect
    dscmd.Fill(ds, sqlselect)

    the error comes at
    dscmd.SelectCommand.CommandText = sqlselect
    why??

    thanks

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Where is dscmd declared at? You must create an instance of it before using it.

    Dim dscmd As New Dataset()

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    83
    I defined them as:

    Public dscmd As New OleDb.OleDbDataAdapter()
    Public ds As New DataSet()

  4. #4
    Frenzied Member mar_zim's Avatar
    Join Date
    Feb 2004
    Location
    Toledo Cebu City.
    Posts
    1,416
    Originally posted by Sheikha
    I defined them as:

    Public dscmd As New OleDb.OleDbDataAdapter()
    Public ds As New DataSet()
    try to do like this:
    VB Code:
    1. Public dscmd As OleDb.OleDbDataAdapter
    2.  
    3. dscmd = New OleDb.OleDbDataAdapter("select * from subarea where upper (code) ='" & UCase(ac) & "' ",conn1)

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You are referencing the SelectCommand of the DataAdapter before it is set to anything. Try:
    VB Code:
    1. 'instead of this
    2. dscmd.SelectCommand.CommandText = sqlselect
    3.  
    4. 'use this
    5. dscmd.SelectCommand=del

    Also there is no need to Execute this command before the fill since it doesn't do anything and gets executed again during the fill. So you can remove this:
    VB Code:
    1. conn1.Open()
    2. del.ExecuteNonQuery()
    3. conn1.Close()

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Posts
    83
    thanks... it works...

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