Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

problem on closing form in vb.net (Object reference not set to an instance of an object.)

Posted on 2009-04-02
6
Medium Priority
?
319 Views
Last Modified: 2013-11-26
hi,
 
i have an error when closing a form, the error is

Object reference not set to an instance of an object.

i have included the code below and the line of code the error comes from is

 voc = curRow.Row.Item(1)

how do i overcome this, im stuck. have tried setting the selected index value of the combox on the exit button but this does not work

any ideas?

thanks in advance
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 
        Dim curRow As DataRowView = ComboBox1.SelectedItem
        Dim voc
        Dim SQLString As String
        Dim dtevents As New DataTable()
        Dim dbDataAdapter As OleDbDataAdapter
        'Dim ConnectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=A470s media.mdb;Persist Security Info=True"
        ' ComboBox1Event.ValueMember 
        'Dim ConnectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\Desktop\Copy of vb 30th march\A470s Media Manager\A470sMedManager\A470s media.mdb;Persist Security Info=True"
        voc = curRow.Row.Item(1)
        'events = Me.ComboBox1Event.SelectedIndex + 1
        'events = Me.ComboBox1Event.SelectedItem
        SQLString = "SELECT * FROM [MediaAsset] WHERE [Vocalist Code] = " & voc & ""
        dbDataAdapter = New OleDbDataAdapter(SQLString, ConnectString)
        dbDataAdapter.Fill(dtevents)
        Dgvsearch.DataSource = dtevents
        ListBox3.DataSource = dtevents
        ListBox3.DisplayMember = "AssetFileName"
        ListBox3.ValueMember = "AssetSource"

Open in new window

0
Comment
Question by:kipl20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24050754
Try include this
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 
If Me.ComboBox1.SelectedIndex <> -1 Then
   'you code
End If
 
End Sub

Open in new window

0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24050765
Or
Dim curRow As DataRowView = ComboBox1.SelectedItem
If curRow Isnot Nothing Then
   'You code
End if

Open in new window

0
 

Author Comment

by:kipl20
ID: 24050980
hi, thanks for the reply but his doesnt seem to change any thing. my comboboxes are filled wit data from my access database using the code supplied. so i have a search from and on this form is a combobox, if the combobox text is Vocalist then it will fill another combo with the data.

does this have anything to do with it?
 ElseIf Me.ComboBox3.Text = "Vocalist" Then
                     Dim dbConn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(strConn)
            dbConn.Open()
            Dim DSet As New DataSet, SQLStr As String
            Dim cmd As System.Data.OleDb.OleDbCommand
            Dim dbAdaptr As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
            Dim tTbl As DataTable
            With dbAdaptr
                .TableMappings.Add("Table", "Vocalist ")
                SQLStr = "Select [Vocalist Name],[Vocalist Code] from Vocalist"
                cmd = New System.Data.OleDb.OleDbCommand(SQLStr, dbConn)
                cmd.CommandType = CommandType.Text
                .SelectCommand = cmd
                .Fill(DSet)
                .Dispose()
            End With
            ' DSet.AcceptChanges() ' --> This line is useless
            tTbl = DSet.Tables.Item(0)
            DSet.Dispose()
            dbConn.Close()
 
            'fill out array by Event Names for combobox
            ComboBox1.DataSource = tTbl
            ComboBox1.DisplayMember = "Vocalist Name"
            ComboBox1.ValueMember = "Vocalist Code"
            'ComboBox1Event.SelectedItem = Nothing
            Me.ComboBox1.Show()
            Me.Label1.Show()
            DataGridView1.Hide()
            ComboBox1.Text = "---Select---"
            txtSearchEvent.Hide()
            txtSearchAr.Hide()
            txtSearchVoc.Show()
            Label2.Show()
            Me.Label1.Text = "Search By Vocalist"
            ListBox3.DataSource.clear()

Open in new window

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 48

Accepted Solution

by:
jpaulino earned 2000 total points
ID: 24051162
Have you tried ?
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 
Dim curRow As DataRowView = ComboBox1.SelectedItem
If curRow Isnot Nothing Then
   ' You code
End if
 
End Sub

Open in new window

0
 

Author Comment

by:kipl20
ID: 24051178
hi sorry jpaulino i read your code wrong, i was putting it down as

 Dim curRow As DataRowView = ComboBox1.SelectedItem
If curRow Isnot Nothing Then
   'You code
else
voc = curRow.Row.Item(1)
End if

instead of the other way round which works, i think i was readin the isnot nothing as it is nothing

thanks alot
 
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24051238
Glad I could help!
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question