Category: VB.Net

Visual Basic Database Connection and Insert Query

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

VB.Net database connection MS Access

VB.Net code to do data base connection with MS Access 2010 Private Sub btnSave_Click(sender AsSystem.Object, e AsSystem.EventArgs) HandlesbtnSave.Click         MsgBox(“Sure! Save permanently in database”, MsgBoxStyle.Information, “SAVE”)         Dim cnn As OleDbConnection= New OleDbConnection         Dim cmd As OleDbCommand= New OleDbCommand         DimconnString As String         connString = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source = E:aDBAtndcDB.accdb”      […]