Command Execution

G

Guest

I think I'm missing an execute command here. Please help.

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Me.Label1.Text = ListBox1.SelectedItem.Value()
Me.DataGrid1.Visible = False
Me.MySqlCommand2.CommandText = "select * from filename where
Customer_id=" + ListBox1.SelectedItem.Value
Me.MySqlDataTable2.SelectCommand = Me.MySqlCommand2
Me.DataSet11.Reset()
Me.MySqlDataAdapter2.Fill(DataSet11)
DataGrid1.DataSource = DataSet11
DataGrid1.DataBind()
Me.DataGrid1.Visible = True
End Sub
 
G

Guest

..NET 2.0, I assume?

Since you are not using one of the new DataSource objects, I would venture
that you need to open the connection before the Fill() and then close it.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
G

Guest

Thanks. I've done as you suggest, however, I still need to execute the
command text. How do I do this within the context of my existing code?
 
G

Guest

My code so far is:

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Me.Label1.Text = ListBox1.SelectedItem.Value()
Me.DataGrid1.Visible = False
Me.MySqlCommand2.CommandText = "select * from filename where
Customer_id=" + ListBox1.SelectedItem.Value
Me.MySqlDataTable2.SelectCommand = Me.MySqlCommand2
Me.DataSet11.Reset()
Me.MySqlDataAdapter2.Fill(DataSet11)
DataGrid1.DataSource = DataSet11
' DataGrid1.DataBind()
Me.DataGrid1.Visible = True
End Sub

But my datagrid remains the same. Any ideas?
 
G

Guest

The correct code is:

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Dim Cust_id As String
Cust_id = "select * from filename where Customer_id=" +
ListBox1.SelectedItem.Value()
Me.DataGrid1.Visible = False
Me.MySqlConnection1.Open()
Me.MySqlCommand1.CommandText = Cust_id
Me.MySqlDataTable1.SelectCommand = Me.MySqlCommand1
Me.MySqlDataAdapter1.Fill(DataSet11)
Me.MySqlConnection1.Close()
DataGrid1.DataSource = DataSet11
DataGrid1.DataBind()
Me.DataGrid1.Visible = True
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

parameters 0
DDL and DataGrid 1
ListBox index values 6
How to fix something on a web page 0
Error "Login failed for user ..." 1
trouble with web forms 2
listboxes 0
parent child dropdownlists acting oddly 1

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top