|
-
Dec 14th, 2005, 04:47 PM
#1
Thread Starter
Member
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.
-
Dec 14th, 2005, 04:55 PM
#2
Re: How do i use vb.net variables in a OleDbCommand select statement?
What are you doing with the dataset after you populate it?
-
Dec 14th, 2005, 05:03 PM
#3
Thread Starter
Member
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.
-
Dec 14th, 2005, 05:04 PM
#4
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.
-
Dec 14th, 2005, 05:07 PM
#5
Thread Starter
Member
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.
-
Dec 14th, 2005, 05:09 PM
#6
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?
-
Dec 14th, 2005, 05:11 PM
#7
Thread Starter
Member
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?
-
Dec 14th, 2005, 05:14 PM
#8
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.
-
Dec 14th, 2005, 05:18 PM
#9
Thread Starter
Member
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
-
Dec 14th, 2005, 05:24 PM
#10
Thread Starter
Member
Re: How do i use vb.net variables in a OleDbCommand select statement?
I have tried using the update method. it doesnt work either
-
Dec 14th, 2005, 05:25 PM
#11
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")
-
Dec 14th, 2005, 05:41 PM
#12
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
-
Dec 14th, 2005, 05:47 PM
#13
Thread Starter
Member
Re: How do i use vb.net variables in a OleDbCommand select statement?
ok. i got it working. thanks a lot
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|