Error : system.nullreferenceexception

Discussion in '.NET' started by Ruchi22, Sep 23, 2011.

  1. Ruchi22

    Ruchi22

    Joined:
    Sep 23, 2011
    Messages:
    1
    Hello..I am developing a windows application in vb.net and getting an error of system.nullreference exception.
    I am trying to insert data in the database, insertion occurs in the first go. But, when i stop the porgram and re-run, i get the exception. Can anybody please help me with this ? Here is the code :

    Imports System.Data
    Imports System.Data.OleDb
    Imports System.EventArgs
    Imports System.Data.OleDb.OleDbCommand
    Imports System.Data.OleDb.OleDbConnection

    Public Class ContactInfo_supp
    Inherits System.Windows.Forms.Form

    Dim Message As String
    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand



    Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click

    Try
    'MsgBox("Open")
    cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;Data Source=E:\Project-Hemtech\HemDatabase1.mdb;")
    cn.Open()
    cmd = New OleDbCommand("insert into contactinfo(usertype,compname,compadd,compcity,comppin,compphcode,compph,compfaxcode,compfax,compmail,compsite,compregoff,compfact,products,interest,region,place,contper1,comprole1,compemail1,contnum1,ext1,mobnum1,contper2,comprole2,compemail2,contnum2,ext2,mobnum2,contper3,comprole3,compemail3,contnum3,ext3,mobnum3,weeklyoff,vat,cst,pan,ecc,commissionerate,range,division,servicetax,bankname,bankbranch,accnum,rtgs,instrname,modelnum,installdate,amc,callibration,period,expdate) values ('Supplier','" & textBox1.Text & "','" & textBox2.Text & "','" & textBox39.Text & "','" & textBox41.Text & "','" & textBox45.Text & "','" & textBox3.Text & "','" & textBox4.Text & "','" & textBox46.Text & "','" & textBox5.Text & "','" & textBox6.Text & "','" & textBox7.Text & "','" & textBox8.Text & "','" & textBox42.Text & "','" & textBox43.Text & "','" & ComboBox1.SelectedItem.ToString() & "','" & textBox44.Text & "','" & textBox9.Text & "','" & textBox10.Text & "','" & textBox47.Text & "','" & textBox11.Text & "','" & textBox12.Text & "','" & textBox13.Text & "','" & textBox18.Text & "','" & textBox17.Text & "','" & textBox48.Text & "','" & textBox16.Text & "','" & textBox15.Text & "','" & textBox14.Text & "','" & textBox23.Text & "','" & textBox22.Text & "','" & textBox49.Text & "','" & textBox21.Text & "','" & textBox20.Text & "','" & textBox19.Text & "','" & textBox50.Text & "','" & textBox25.Text & "','" & textBox26.Text & "','" & textBox27.Text & "','" & textBox28.Text & "','" & textBox29.Text & "','" & textBox30.Text & "','" & textBox31.Text & "','" & textBox32.Text & "','" & textBox33.Text & "','" & textBox34.Text & "','" & textBox35.Text & "','" & textBox36.Text & "','" & textBox37.Text & "','" & textBox38.Text & "','" & dateTimePicker1.Text & "','" & ComboBox2.SelectedItem.ToString() & "','" & ComboBox3.SelectedItem.ToString() & "','" & textBox40.Text & "','" & dateTimePicker2.Text & "')", cn)
    cmd.ExecuteNonQuery()

    MsgBox("Your Account Created Successfully ")

    Dim f9 As New Action()
    f9.Show()
    Me.Hide()

    Catch myException As Exception

    MsgBox("No Record Inserted" + myException.ToString())

    Finally
    'MsgBox("Closing Connection")

    cn.Close()
    End Try

    End Sub
    Ruchi22, Sep 23, 2011
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William
    Replies:
    0
    Views:
    1,586
    William
    Aug 10, 2004
  2. msnews.microsoft.com

    Help with System.NullReferenceException

    msnews.microsoft.com, Jul 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    562
    msnews.microsoft.com
    Jul 16, 2003
  3. Manny
    Replies:
    1
    Views:
    431
    Lau Lei Cheong
    Aug 2, 2004
  4. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    Whats the error:- System.NullReferenceException:

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 31, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    4,576
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Nov 1, 2004
  5. EmmaKate
    Replies:
    0
    Views:
    593
    EmmaKate
    Jan 8, 2008
Loading...

Share This Page