dcsimg
Results 1 to 4 of 4

Thread: [RESOLVED] object reference not set to an instance of object

  1. #1

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,560

    Resolved [RESOLVED] object reference not set to an instance of object

    hey
    im trying to load some data to my combobox i get this error"object reference not set to an instance of object"
    what is wrong?
    this is my code
    Code:
    Option Strict On
    Option Explicit On
    Imports System.Data.Sql
    Imports System.Data
    Imports System.Data.SqlClien
    
    
    
    
        Dim Cmd As SqlCommand
        Dim Dr As SqlDataReader
            Dim CNN As SqlConnection
            CNN = New SqlConnection("Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Tech\Desktop\vbnet\WindowsApplication1\WindowsApplication1\Beauty.mdf;Integrated Security=True")
            Try
                Dim Sqlstr As String = "select * from Db_Customers"
                'CNN.Open()
                Cmd = New SqlCommand(Sqlstr, CNN)
                Cmbusers.Items.Clear()
    
                Do While Dr.Read
                    Cmbusers.Items.Add(Dr.GetValue(1).ToString)
                Loop
    
            Catch ex As Exception
    
                MsgBox(ex.Message)
                CNN.Close()
    tnx for any help
    salsa

  2. #2
    Bad man! ident's Avatar
    Join Date
    Mar 2009
    Location
    Cambridge
    Posts
    5,143

    Re: object reference not set to an instance of object

    Code:
     Dim Dr As New SqlDataReader

  3. #3

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,560

    Re: object reference not set to an instance of object

    Quote Originally Posted by ident View Post
    Code:
     Dim Dr As New SqlDataReader
    i tried that i get error
    overload resolution failed because no 'new' is accessible

  4. #4

    Thread Starter
    Enjoy the moment
    Join Date
    Feb 2011
    Location
    Barrio Del pilar madrid spain
    Posts
    4,560

    Re: object reference not set to an instance of object

    well i got it working at last
    Code:
     Dr = Cmd.ExecuteReader

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width