By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,325 Members | 1,179 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,325 IT Pros & Developers. It's quick & easy.

how to insert data into acess from vb2005

P: 1
'this is my code plz guys help how to save data from vb 2005 and other this that i am able to view the data from acess but i am not able save to acess i dont whether my code for save is correct of not ( iam using vb2005 as front end and MS acess as by back end)

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Database1_beDataSet.Table1' table. You can move, or remove it, as needed.
Me.Table1TableAdapter.Fill(Me.Database1_beDataSet. Table1)
End Sub

Private Sub cmdnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdnew.Click
Me.Table1BindingSource.AddNew()
End Sub

Private Sub cmdfirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdfirst.Click
Me.Table1BindingSource.MoveFirst()
If (Val(TextBox1.Text) = 1) Then
MsgBox("This first record")
End If
End Sub

Private Sub cmdprevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdprevious.Click
Me.Table1BindingSource.MovePrevious()
If (Val(TextBox1.Text) = 1) Then
MsgBox("This first record")
End If
End Sub

Private Sub cmdlast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdlast.Click
Me.Table1BindingSource.MoveLast()
End Sub

Private Sub cmdnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdnext.Click
Me.Table1BindingSource.MoveNext()
End Sub

Private Sub cmdsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsave.Click
Dim consql3 As OleDb.OleDbConnection = _
New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLED B.4.0;Data Source=|DataDirectory|\Database1_be.mdb;")
'Caminho da base de dados
consql3.Open() 'abre a conexao com o banco
'query de busca
Dim sql3 As String = "INSERT INTO Table1(name, class, dept, physis, chemistry, maths) VALUES('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "')"
Dim comam3 As OleDb.OleDbCommand
comam3 = New OleDb.OleDbCommand(sql3, consql3)
Dim adapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(comam3)

comam3 = New OleDb.OleDbCommand(sql3, consql3)
consql3.Close()
End Sub

Private Sub cmdclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdclear.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
End Sub
End Class
Sep 18 '08 #1
Share this Question
Share on Google+
1 Reply

debasisdas
Expert 5K+
P: 8,127
are you getting any error with your code ?
Sep 19 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.