Sunteți pe pagina 1din 5

'With this project, you are able to make simple concept to access msaccess database.

thanks 'Comment me i am begginer at zero state at programing. 'my contact add is id.complex2006@gmail.com Imports System.Data.OleDb Public Class Form1 Inherits System.Windows.Forms.Form Dim cn As OleDbConnection Dim cmd As OleDbCommand Dim dr As OleDbDataReader Dim ds As DataSet Dim da As OleDbDataAdapter Dim STrPath = System.IO.Directory.GetCurrentDirectory & "\Emp.mdb" Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load jdcomplex() Me.BindingContext(ds, "ms").Position = 0 Label1.Text = (Me.BindingContext(ds, "ms").Position + _ 1).ToString & " of " & Me.BindingContext(ds, _ "ms").Count.ToString End Sub Sub jdcomplex() Try cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0; data source='" & STrPath & "';") cmd = New OleDbCommand("select * from Table1 order by eno asc") cn.Open() cmd.Connection = cn da = New OleDbDataAdapter("select * from Table1", cn) ds = New DataSet("ms") da.Fill(ds, "ms") 'BindingSource1.DataSource = ds 'BindingSource1.DataMember = "ms" kamal() Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Information, "") End End Try cn.Close() End Sub Sub kamal() TextBox1.DataBindings.Add("text", ds, "ms.eno") TextBox2.DataBindings.Add("text", ds, "ms.ename") TextBox3.DataBindings.Add("text", ds, "ms.department") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0;

data source='" & STrPath & "';") cn.Open() Dim str As String = "insert into table1 values(" & CInt(TextBox1.Text) & ",'" & TextBox2.Text & "','" & _ TextBox3.Text & "')" 'string stores the command and CInt is used to convert number to string cmd = New OleDbCommand(str, cn) Dim temp As Integer = cmd.ExecuteNonQuery 'displays number of records inserted If temp > 0 Then MsgBox("Data Are Added Successfully") TextBox1.DataBindings.Clear() TextBox2.DataBindings.Clear() TextBox3.DataBindings.Clear() jdcomplex() Else MsgBox("Try Again")

End If Catch ex As Exception End Try cn.Close() Label1.Text = (Me.BindingContext(ds, "ms").Position + _ 1).ToString & " of " & Me.BindingContext(ds, _ "ms").Count.ToString

End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim ans = MsgBox("Do you really want to delete this record?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "") If ans = vbNo Then Exit Sub End If Try cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0; data source='" & STrPath & "';") cn.Open() Dim str As String = "delete from table1 where eno=" & TextBox1.Text & "" 'string stores the command and CInt is used to convert number to string cmd = New OleDbCommand(str, cn) Dim temp As Integer = cmd.ExecuteNonQuery 'displays number of records inserted If temp > 0 Then MsgBox("Data Are deleted Successfully")

TextBox1.DataBindings.Clear() TextBox2.DataBindings.Clear() TextBox3.DataBindings.Clear() jdcomplex() Else MsgBox("Try Again")

End If Catch ex As Exception End Try cn.Close() Label1.Text = (Me.BindingContext(ds, "ms").Position + _ 1).ToString & " of " & Me.BindingContext(ds, _ "ms").Count.ToString End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox1.Focus() Label1.Text = "Adding Progress" End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox1.DataBindings.Clear() TextBox2.DataBindings.Clear() TextBox3.DataBindings.Clear() jdcomplex() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Me.BindingContext(ds, "ms").Position = 0 Label1.Text = (Me.BindingContext(ds, "ms").Position + _ 1).ToString & " of " & Me.BindingContext(ds, _ "ms").Count.ToString End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Me.BindingContext(ds, "ms").Position = Me.BindingContext(ds, "ms").Count - 1 Label1.Text = (Me.BindingContext(ds, "ms").Position + _ 1).ToString & " of " & Me.BindingContext(ds, _ "ms").Count.ToString End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Me.BindingContext(ds, "ms").Position = Me.BindingContext(ds, "ms").Position - 1 Label1.Text = (Me.BindingContext(ds, "ms").Position + _ 1).ToString & " of " & Me.BindingContext(ds, _ "ms").Count.ToString End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Me.BindingContext(ds, "ms").Position = Me.BindingContext(ds, "ms").Position + 1 Label1.Text = (Me.BindingContext(ds, "ms").Position + _ 1).ToString & " of " & Me.BindingContext(ds, _ "ms").Count.ToString End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click cn.Open() Dim sql As String = "update Table1 set ename='" & TextBox2.Text & "',department=' " & TextBox3.Text & "' where eno=" & CInt(TextBox1.Text) & "" Dim ct As OleDbCommand ct = New OleDbCommand(sql, cn) ct.ExecuteNonQuery() cn.Close() End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click TextBox1.DataBindings.Clear() TextBox2.DataBindings.Clear() TextBox3.DataBindings.Clear() jdcomplex() Label1.Text = (Me.BindingContext(ds, "ms").Position + _ 1).ToString & " of " & Me.BindingContext(ds, _ "ms").Count.ToString End Sub

Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click End Sub Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click TextBox1.DataBindings.Clear() TextBox2.DataBindings.Clear() TextBox3.DataBindings.Clear() Try cn = New OleDbConnection("Provider=microsoft.jet.oledb.4.0; data source='" & STrPath & "';") cmd = New OleDbCommand("select * from Table1 ") cn.Open() cmd.Connection = cn da = New OleDbDataAdapter("select * from Table1 where eno=" & CInt(TextBox4.Text) & "", cn) ds = New DataSet("ms") da.Fill(ds, "ms") 'BindingSource1.DataSource = ds 'BindingSource1.DataMember = "ms" kamal() If TextBox1.Text = "" Then ds.Clear() End If Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Information, "") End End Try cn.Close() Label1.Text = "searching" End Sub End Class

S-ar putea să vă placă și