Hello,

I am trying this..

Imports System.Data.OleDb

Public Class Form1
    Dim conn As OleDbConnection
    Dim cmd As OleDbCommand


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        conn = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=c:\nikhil.mdb")
        conn.Open()
        Dim row As DataRowView=ComboBox1.SelectedValue



        Dim row1 As DataRowView = ComboBox2.SelectedValue
        Dim row2 As DataRowView = ComboBox3.SelectedValue


        cmd = New OleDbCommand("insert into table1 values( " & row.Row("id").ToString & ",' " & row1.Row("name").ToString & " ', " & row2.Row("salary").ToString & ")", conn)
        cmd.ExecuteNonQuery()

        conn.Close()




    End Sub

I get an error: object reference not set to an instance of an object

I guess one of the combobox is not selected and variables "row", "row1" or "row2" has nothing (Null).

So use IsNothing method to test an object is missing or not.

If IsNothing(row)  Then
   //Select 1st combobox value
   return 
 End If
 ...
 If IsNothing(row1)  Then
   //Select 2nd combobox value
   return 
 End If
 ...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.