How to create database connection in Visual Basic ?
Here, we are going to use Visual Basic 2010 and MS Access 2010.
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
Dim cnn As OleDbConnection = New OleDbConnection
Dim cmd As OleDbCommand = New OleDbCommand
Dim connString As String
connString = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source = C:ARAttendenceDB.accdb”
cnn.ConnectionString = connString
cmd.Connection = cnn
cnn.Open()
cmd.CommandText = “INSERT INTO Attendence ([dat], [totalPresent], [one])” + ” VALUES (‘” & dt.Text & “‘, ‘” & lblTotalPresent.Text & “‘, ‘” & comboBox1.Text & “‘)”
cmd.ExecuteNonQuery()
cnn.Close()
End Sub