SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Other Forums
 MS Access
 populate datagridview based on combobox
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Leonel
Starting Member

10 Posts

Posted - 06/17/2012 :  13:18:11  Show Profile  Reply with Quote
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 - 06/20/2012 :  21:48:58  Show Profile  Reply with Quote

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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000