find row in dataset

Richnl

Well-known member
Joined
Mar 20, 2007
Messages
93
Programming Experience
Beginner
I have a situation I can't get out of

Imagine I have two tables (customers,customersettings)

Customers has a primarykey called customerID and is related to customersettings with foreignkeyconstraint

CustomerSettings does not have a primarykey

I have to find a pricevalue in customersettings according to a customerID value in a textbox

I am trying to use the find methods, sofar no luck (see below)
also, if I am trying to count the rows in the table it comes up with 0 except
when i have a datagridview on the form..?

Can anybody help me out here, what am I missing?

VB.NET:
[SIZE=2][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] srch [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = Val(LedenIDTextBox.Text).ToString
srch = [/SIZE][SIZE=2][COLOR=#a31515]"CustomerID= '"[/COLOR][/SIZE][SIZE=2] & srch & [/SIZE][SIZE=2][COLOR=#a31515]"'"
[/COLOR][/SIZE][/SIZE] 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] matches() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataRow = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TDataSet.Tables _([/SIZE][SIZE=2][COLOR=#a31515]"customersettings"[/COLOR][/SIZE][SIZE=2]).Select(srch)[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dv [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataView = [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TDataSet.cutomersettings.DefaultView[/SIZE]
dim i as integer= [SIZE=2]Val(LedenIDTextBox.Text)
[/SIZE][SIZE=2]dim index as integer= -1[/SIZE]
[SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE][SIZE=2] dv[/SIZE]
[SIZE=2].Sort = [/SIZE][SIZE=2][COLOR=#a31515]"CustomerID"[/COLOR][/SIZE]
[SIZE=2]Index = .Find(i)[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] Index > -1 [/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE][SIZE=2] MessageBox.Show(dv(Index)([/SIZE][SIZE=2][COLOR=#a31515]"Price"[/COLOR][/SIZE][SIZE=2]).ToString)[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]With[/COLOR][/SIZE]

thanks, Richard
 
Last edited:
Can anybody help me out here, what am I missing?
Sorry, I missed to fill the tableDataAdapter
It's automaticly created when you drag a table to the form.
There was no need for a datagridview for the table, so I deleted the gridview aswell as the code to fill the adapter in the load_form_event.
By doing so, I ignored the fact that I still needed the TableDataAdapter to querie the dataset.

I still get mixed up in using the components!

thanks, Richard
 
Back
Top