How do i use vb.net variables in a OleDbCommand select statement?
My code is:
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton1.Click
Try
Dim OleDbCommand1 As New OleDb.OleDbCommand("SELECT * FROM Table1 WHERE Field = '" & TextBox1.Text & "' ", OleDbConnection)
Dim OleDbDataAdapter1 As New OleDb.OleDbDataAdapter(OleDbCommand1)
OleDbDataAdapter1.Fill(DataSet1)
Catch oledbex As OleDb.OleDbException
MessageBox.Show(oledbex.Message)
End Try
End Sub
A datagrid is being used to show the information. I want the grid to show the fields where the text in the textbox matches the text in a database field. So far when i click the button nothing happens. What am i doing wrong. please help me.
Re: How do i use vb.net variables in a OleDbCommand select statement?
What are you doing with the dataset after you populate it?
Re: How do i use vb.net variables in a OleDbCommand select statement?
Im not doing anything with it. should i dispose of it? By the way, this is the first time ive ever had to use a datagrid or a sql statement that involved variables. i have no clue what to do.
Re: How do i use vb.net variables in a OleDbCommand select statement?
the dataset is a data object, it's an intermediary between your database and the datagrid control.
Set the datagrid's datasource proeprty to the dataset's table you want to bind to.
If this is a webform datagrid, check out the link in my signature for some really good info.
Re: How do i use vb.net variables in a OleDbCommand select statement?
The dataset is bound to the datagrid. The datasource is set to the dataset and the datamember is set to the table. This is where i am getting confused. to me it looks like the code should work.
Re: How do i use vb.net variables in a OleDbCommand select statement?
In the example you gave, none of that is happening. You're filling the dataset with the adapter and then the try/catch/end try is done. Can you give more codewhere you're setting all these properties?
Re: How do i use vb.net variables in a OleDbCommand select statement?
the dataset is created in design mode. I have edited the properties of the datagrids datasource and datamember in design mode as well. should i be doing it in code?
Re: How do i use vb.net variables in a OleDbCommand select statement?
IMO - I do, it's easier to follow instead of digging through controls, but that's up to you.
Try just YourDataGridName.DataBind() right after you fill the dataset. Since everything is already looking the right direction, you might just need to tell it to go.
Re: How do i use vb.net variables in a OleDbCommand select statement?
How do i call the databind method. its not coming up in intellisense
Re: How do i use vb.net variables in a OleDbCommand select statement?
I have tried using the update method. it doesnt work either
Re: How do i use vb.net variables in a OleDbCommand select statement?
Webforms datagrids will allow databind, winforms are different; sorry.
You can try Me.Refresh(). If everything is lined up right (query, datasources, ect), it should be simple as that.
If not, I would try hardcoding it in code, just for gits and shiggles to see if it might be a design-view configuration issue.
VB Code:
Dim dataset1 As New DataSet
Me.DataGrid1.DataSource = dataset1.Tables("SourceTableName")
Re: How do i use vb.net variables in a OleDbCommand select statement?
Before you refill your dataset.... clear it first DataSet.Clear ... that will clear out the existing data (if you have multiple datatables, you can just .Clear the one table you are dealing with). Then you can fill your dataset, and rebind it back to your grid.
About half way down this article I describe this phenominon (sp?)
http://www.developerkb.com/modules/w...p?articleid=58
When I was doing this, it looked like it wasn't doing anything either, but what I found was that it kept adding to my datatable.... and if I sorted, I could see the dupes.
-tg
Re: How do i use vb.net variables in a OleDbCommand select statement?
ok. i got it working. thanks a lot