populate values from a database!!
Hi
I need help to populate values from a database(Access) in to vb.net form. after selecting a field from first form , the next form should display all the parameters used in the selected field from the data base. Also if do editing it shppuld be updated in the database.
Find the code below!!!
Thanks in advance!
Code:
Public Class Editdetails
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cn As New System.Data.OleDb.OleDbConnection
Dim cm As New System.Data.OleDb.OleDbCommand
Dim form As New Fielddetails
Dim rd As System.Data.OleDb.OleDbDataReader
Dim tbl_name As String = "Fld_detail_" & Datamaker.Application_Datamaker_ListBox.SelectedItem
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\175943\Desktop\database1.accdb;Persist Security Info=False;"
Try
cn.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
cm.Connection = cn
cm.CommandText = "select * from (" & tbl_name & ") where Start_loc like '" & form.ListBox_Fielddetails.SelectedItem & "%'"
rd = cm.ExecuteReader()
While rd.Read
Me.datatype.SelectedItem = rd("Datatype").ToString
Me.fieldname.Text = rd("Field_var").ToString
End While
rd.Close()
End Sub
Re: populate values from a database!!
Is it working now?What is the problem now?
Re: populate values from a database!!
Re: populate values from a database!!
Form is loading correctly... but the values are not populating from the database:-(
Re: populate values from a database!!
Code:
Me.datatype.SelectedItem = rd("Datatype").ToString
Me.fieldname.Text = rd("Field_var").ToString
Re: populate values from a database!!
ramesh017,
Have a look here.