hi , here i am trying to insert values to the database but the combobox values are not adding when they are null . How to insert the combobox value when it is null. I am getting the error as "Object reference not set to an instance of an object."
ocon = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Customer.mdb")
ocon.Open()
Dim s1 As String
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or TextBox6.Text = "" Then
MsgBox("Please enter all the fields")
Else
s1 = "insert into Customertable(cusid,cusname,cusdivision,cuslocation,cuscountry,custypeofproj,stage1,stage2,stage3,stage4,stage5,stage6,stage7,stage8,stage9,stage10,stage11,stage12,stage13,stage14)values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + ComboBox1.SelectedItem.ToString() + "','" + ComboBox2.SelectedItem.ToString() + "','" + ComboBox3.SelectedItem.ToString() + "','" + ComboBox4.SelectedItem.ToString() + "','" + ComboBox5.SelectedItem.ToString() + "','" + ComboBox6.SelectedItem.ToString() + "','" + ComboBox7.SelectedItem.ToString() + "','" + ComboBox8.SelectedItem.ToString() + "','" + ComboBox9.SelectedItem.ToString() + "','" + ComboBox10.SelectedItem.ToString() + "','" + ComboBox11.SelectedItem.ToString() + "','" + ComboBox12.SelectedItem.ToString() + "','" + ComboBox13.SelectedItem.ToString() + "','" + ComboBox14.SelectedItem.ToString() + "')"
ocmd.ExecuteNonQuery()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
ComboBox1.SelectedIndex = -1
ComboBox2.SelectedIndex = -1
ComboBox3.SelectedIndex = -1
ComboBox4.SelectedIndex = -1
ComboBox5.SelectedIndex = -1
ComboBox6.SelectedIndex = -1
ComboBox7.SelectedIndex = -1
ComboBox8.SelectedIndex = -1
ComboBox9.SelectedIndex = -1
ComboBox10.SelectedIndex = -1
ComboBox11.SelectedIndex = -1
ComboBox12.SelectedIndex = -1
ComboBox13.SelectedIndex = -1
ComboBox14.SelectedIndex = -1
TextBox1.Focus()
MsgBox("Successfully inserted")
End If