ben Level: Protégé
 Registered: 12-05-2006 Posts: 6
|
Re: Database with MS access in vb .net
Imports System
Imports System.Data
Imports System.Data.Oledb
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Add_Btn_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Add_Btn.Click
Try
Me.OleDbDataAdapter1.InsertCommand.CommandText = "INSERT INTO Test (Name, Block, Floor, Hp)" + "VALUES('" + Me.Name_textbox.Text + "','" + Me.Block_textbox.Text + "' ,'" + Me.Floor_textbox.Text + "' ,'" + Me.Hp_textbox.Text + "')"
Me.OleDbConnection1.Open()
Me.OleDbDataAdapter1.InsertCommand.Connection = OleDbConnection1
Me.OleDbDataAdapter1.InsertCommand.ExecuteNonQuery()
Me.OleDbConnection1.Close()
MessageBox.Show("Record Added")
Me.Name_textbox.Text = ""
Me.Block_textbox.Text = ""
Me.Floor_textbox.Text = ""
Me.Hp_textbox.Text = ""
Catch exp As System.Data.OleDb.OleDbException
Me.OleDbConnection1.Close()
MessageBox.Show(exp.ToString)
End Try
End Sub
End Class
Can anyone help me with this??
I entered the necessary data into the text boxes and clicked the add_btn button....it says record added but i check my database table but the record is not added inside?? Thanks
|