I am trying to do the simplest thing in VB.NET 2005.
I am tying to connect to a database and make some values write into a table (the code is below)
Every time I run the application I get the error 'ExecuteNonQuery: Connection property has not been initialized.' from the command.ExecuteNonQuery() command.
If i don’t put it in, there is no error but no data is passed to the database, if I do then it fails and doesn’t run.
Any Ideas would be grateful
Please keep it simple, first time I have ever needed to play with programing so you could say that I a newbie.
I am tying to connect to a database and make some values write into a table (the code is below)
Every time I run the application I get the error 'ExecuteNonQuery: Connection property has not been initialized.' from the command.ExecuteNonQuery() command.
If i don’t put it in, there is no error but no data is passed to the database, if I do then it fails and doesn’t run.
Any Ideas would be grateful
Please keep it simple, first time I have ever needed to play with programing so you could say that I a newbie.
VB.NET:
Private Sub newcusnextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles newcusnextButton.Click
Dim title As String = titleList.Text
Dim firstname As String = firstnameText.Text
'Dim surname As String = surnameText.Text
'Dim houseNo As String = housenoText.Text
'Dim address1 As String = address1Text.Text
'Dim address2 As String = address2Text.Text
'Dim county As String = countyComboBox.Text
'Dim postcode As String = postcode1Text.Text
'Dim DofBday As Integer = dayList.Text
'Dim DofBmonth As String = monthList.Text
'Dim DofByear As Integer = yearText.Text
Dim connect As New OleDb.OleDbConnection
connect.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Holiday.mdb"
connect.Open()
MsgBox("A Connection to the Database is now open")
Dim command As New System.Data.OleDb.OleDbCommand
Dim sql
sql = ("INSERT into tblCustomer(title, firstname, surname, houseno, address1, address2, county, postcode, DofB)" _
& "Values ('" & title & "' , '" & firstname & "'")
command.CommandText = sql
command.ExecuteNonQuery()
connect.Close()
MsgBox("The Connection to the Database is now Closed")
Last edited by a moderator: