Welcome!


Join more than 151,000 members on FunAdvice to ask questions, share advice, photos and make new friends today.
FunAdvice RSS for this page:
Rss_feed

Retriving data from msaccess database

Asked by qqq 2 months ago,

by selecting the employee number in the combobox and click the button1 the details of the relevant employee is to viewed.

my prblm is that giving any employee number the same one is displaying
wt fault with my code!!!
help me

Imports...

System.Data
Imports System.Data.OleDb

Public Class Form2
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim adp As OleDbDataAdapter
Dim ds As New DataSet
' Dim str As String
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con = New OleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\employee.mdb)
adp = New OleDbDataAdapter(select * from table1, con)
adp.Fill(ds)
Dim I As Integer
For I = 0 To ds.Tables(0).Rows.Count - 1
ComboBox1.Items.Add(ds.Tables(0).Rows(I).Item(0))
Next I
con.Close()
' cmd = New OleDbCommand(select * from table1 where eno= index , con)
'dr = cmd.ExecuteReader()
' If (dr.Read()) Then

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

Try
con = New OleDbConnection(Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\employee.mdb)

con.Open()
cmd = New OleDbCommand(select * from table1, con)
dr = cmd.ExecuteReader
While dr.Read()
TextBox1.Text = dr(1)
TextBox2.Text = dr(2)
TextBox3.Text = dr(3)
TextBox4.Text = dr(4)
TextBox5.Text = dr(5)
TextBox6.Text = dr(6)
TextBox7.Text = dr(7)
TextBox8.Text = dr(8)
End While
Catch
End Try
dr.Close()
con.Close()

'cmd = New OleDbCommand(update table1 set firstname=' TextBox1.Text ', lastname=' TextBox2.Text ',paddress=' TextBox3.Text ', phoneno=' TextBox4.Text ',pincode=' TextBox7.Text ',city=' TextBox5.Text ',state=' TextBox6.Text ',age= TextBox8.Text where no= ComboBox1.SelectedItem , con)

'cmd.ExecuteScalar()
'MessageBox.Show(updated)
'con.Close()
' con.Close()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
con.Open()
adp = New OleDbDataAdapter(select * from table1 where no= ComboBox1.SelectedItem , con)
ds.Tables.Clear()
adp.Fill(ds)
display()
' cl()
con.Close()

End Sub
Sub display()
TextBox1.DataBindings.Add(text, ds.Tables(0), firstname)
TextBox2.DataBindings.Add(text, ds.Tables(0), lastname)
TextBox3.DataBindings.Add(text, ds.Tables(0), paddress)
TextBox4.DataBindings.Add(text, ds.Tables(0), phoneno)
TextBox5.DataBindings.Add(text, ds.Tables(0), pincode)
TextBox6.DataBindings.Add(text, ds.Tables(0), city)
TextBox7.DataBindings.Add(text, ds.Tables(0), state)
TextBox8.DataBindings.Add(text, ds.Tables(0), age)

End Sub
'Sub cl()
' TextBox1.DataBindings.Clear()
' TextBox2.DataBindings.Clear()
' TextBox3.DataBindings.Clear()
' TextBox4.DataBindings.Clear()
' TextBox5.DataBindings.Clear()
' TextBox6.DataBindings.Clear()
'TextBox7.DataBindings.Clear()
' TextBox8.DataBindings.Clear()
' End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Form1.Show()
Me.Close()

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Form3.Show()
Me.Close()
End Sub
End Class

Answer this Question: "retriving data from msaccess database"

Your Answer: HTML is not allowed.


Our members said the answers on this page also answer the following questions:


Dim con as new oledbconnection("provider=microsoft.jet.oledb.4.0;data s?, C oledbdataadapter select where?, _con.open( c# msaccess?, Cmd = new oledbcommand syntax ms access?, Textbox1.databindings oledbdatareader?, Me close ms access?, Textbox5.text = ("dr" & (5))

Computers & Tech Photos

:)Lol brunnett bomb shell!data entry provider and enter net publisher

Share this question

Copy and paste this code:
It will display on your blog or site like this:
Retriving data from msaccess database