Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 populate datagridview based on combobox

Author  Topic 

Leonel
Starting Member

10 Posts

Posted - 2012-06-17 : 13:18:11
this code populate the combobox, just fine
code
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database\ReturnEquipment.accdb;Persist Security Info=False;")

Dim CMD1 As New OleDb.OleDbCommand
CMD1.Connection = con

con.Open()

CMD1.CommandText = "SELECT SN from RMA"
Dim miDataReader As OleDb.OleDbDataReader
miDataReader = CMD1.ExecuteReader
Dim dt As New DataTable
dt.Load(miDataReader)
ComboBox1.DataSource = dt
ComboBox1.ValueMember = dt.Columns(0).ToString()
ComboBox1.DisplayMember = dt.Columns(0).ToString()
con.Close()

I want to populae the datagridbview based on the selected value of the combobox
my datagridview is called dgDetails
i tried differents ways and no luck
any help

Leonel
Starting Member

10 Posts

Posted - 2012-06-20 : 21:48:58

Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Database\ReturnEquipment.accdb;Persist Security Info=False;")

Dim myCommand = New OleDbCommand("select * from RMA WHERE SN = @SN")
myCommand.Connection = conn
conn.Open()
myCommand.Parameters.AddWithValue("@sn", ComboBox1.SelectedValue)
Dim ds As Data.DataSet = New Data.DataSet
Dim dr As OleDbDataReader
Dim DA As New OleDbDataAdapter
dr = myCommand.ExecuteReader
myCommand.Connection = conn
DA.Fill(ds, "RMA")
DataGridView1.DataSource = ds

myCommand.dispose()



con.Close()


End Sub
i used this code and i get this error:
The SelectCommand property has not been initialized before calling 'Fill'.
Go to Top of Page
   

- Advertisement -