Reputation: 1
Connection
Conn_String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\UTS.mdb"
conn = New OleDbConnection(Conn_String)
conn.Open()
Query
sqlCmd.Connection = conn
sqlCmd.CommandText = "INSERT into Customer_Master Values (@Cust_ID,@Cust_Name,@Cust_Address,@Cust_ContactNo)"
sqlCmd.Parameters.AddWithValue("@Cust_ID", SqlDbType.Int).Value = Cust_id
sqlCmd.Parameters.AddWithValue("@Cust_Name", SqlDbType.Text).Value = txtcname.Text
sqlCmd.Parameters.AddWithValue("@Cust_Address", SqlDbType.Text).Value = txtcadd.Text
sqlCmd.Parameters.AddWithValue("@Cust_ContactNo", SqlDbType.Int).Value =
txtccontact.Text.ToString
sqlCmd.ExecuteNonQuery()
conn.Close()
Problem
When I Click the button containing the above code it gives me following error..
An unhandled exception of type System.NullReferenceException
occurred in UTS.exe
Additional information: Object reference not set to an instance of an object.
The error is n this line-->sqlCmd.Connection = conn
Upvotes: 0
Views: 131