Posts

Showing posts with the label oledb

How to add a new record using Access database with auto number id?

Image
Clash Royale CLAN TAG #URR8PPP How to add a new record using Access database with auto number id? My VB.Net code is as follows but my code replaces the previous record instead: Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Dim cs As OleDbConnection = New OleDbConnection cs.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + Application.StartupPath + "LoginDB.accdb" cs.Open() Dim cd As OleDbCommand = New OleDbCommand("INSERT INTO LoginTable (Name1,Name2,PNum,Age,Sex) VALUES(@name1,@name2,@num,@age,@sex)", cs) If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or ComboBox1.Text = "" Then MsgBox("Enter all the details!") Else cd.Parameters.AddWithValue("@name1", TextBox1.Text) cd.Parameters.AddWithValue("@name2", TextBox2.Text) cd.Para...