Update Access Database from Textbox

  • Thread starter Thread starter Shawn Jackson via .NET 247
  • Start date Start date
S

Shawn Jackson via .NET 247

Hi, I just starting using VB.NET and I a few textboxes on a form. I want to enter info into the textboxes, click the Add Button and update my Access database. Can't get it to work. Maybe someone
has a good example for me, thanks.
 
Here is a really simplistic example of one form, one button adding a row.

HTH

Terry Burns

-------------------------------------------

'At class level

Private OleDbInsertCommand1 As System.Data.OleDb.OleDbCommand

Private OleDbConnection1 As System.Data.OleDb.OleDbConnection

Private OleDbDataAdapter1 As System.Data.OleDb.OleDbDataAdapter

'Under a button

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

OleDbInsertCommand1 = New System.Data.OleDb.OleDbCommand

OleDbConnection1 = New System.Data.OleDb.OleDbConnection

OleDbInsertCommand1.CommandText = "INSERT INTO [Names] (Name) VALUES ('" &
TextBox1.Text & "');"

OleDbInsertCommand1.Connection = Me.OleDbConnection1

OleDbConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\TESTTB.mdb;User Id=admin;Password=;"

Try

OleDbConnection1.Open()

OleDbInsertCommand1.ExecuteNonQuery()

Catch ex As OleDb.OleDbException

MessageBox.Show(ex.ToString)

End Try

OleDbConnection1.Close()

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top