Link to home
Start Free TrialLog in
Avatar of Brian Pierce
Brian PierceFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Working with Data in Visual Basic 2010

I'm strugging trying to get my head around working with data in Visual BASIC 2010. The specific problems I have at the moment are:

I have a form that reads data from an access table that now looks like this - and it works is as much as I can see the data, navaguie through it etc but how can I

1. Use another text box to allow me to enter a location and display just the data that matches the location

2. How can I select a whole record and add it to another table (by pressing a button)

Any help much appreciated - I can bost the code I have so far (which is not much), if it helps
snap004.jpg
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Can you post a few more details of how you constructed your form and how you are currently getting your data? You should be able apply a filter to the data you are retrieving, either once it is bound or at the source; but the specifics will depend on how you currently have your form working.
Avatar of Brian Pierce

ASKER

OK i've attached the project as it stands so far as a zip file - there is not much in it presently

Essentially there are two tables tbl_master and tbl_allocated which appear side by side on a form

I want to be able to do two things

1. be able to filter the left most table by location - ir I want to put a textbox/combo box on the form, enter a location and then have the dataset on the left update to show only matching records.

2. I want to be able to click the > button and copy the record from the table on the left to the table on the right
(it would be nice to have the option to COPY or MOVE the record)

If I can provide any further help please let me know

( I have had to add .txt to some file extentions as the zip file would not upload to the EE site with the default extentions present - please just remove any .txt extentions)
db1.zip
Here is the main form if it helps
VB2010.jpg
I have explained the way of programatic selecting, filtering and inserting data from/to tables in your post/question "Copying rows from one table to another in Visual Basic 2010".

Now I see more clear what you need. It seems more easy that I thought.

As I see you can do the "select" by using DataSet.Tables(0).Select("ID = " + textID.Text). So, you enter desired row ID in textID. When you execute select statement you get array of Rows with exactly one row (array length will be one). To present it in datagrid on the left side you should "link" datagrid with filtering results.
I do this on following way:
1. Create DataView object using DataTable (of Dataset) and row filter as:
Dim dvr as DataView
dvr = New DataView(ds.Tables(0), "ID = "+desiredID, "ID", DataViewRowState.CurrentRows)
2. Bind your datagrid to the DataView as : yourDataGrid.DataSource = dvr
3. You should take care about presented columns in datagrid

Now, when you enter the ID in above textID box, and refresh datagrid (for example press enter or press the button), the left grid will show filtered row from table1.

COPY or MOVE:
when you press button to copy from left grid to right grid you need to do following:
1. put all desired data (shown in left grid) in some variables.
2. create insert sql command to the table2 (which is presented by right grid)
3. execute insert statement into the table2
4. refresh right grid on the same way as you did it with left grid when you defined desired ID (you have all necessary data for doing this).
OPTIONALY:
if you want to do MOVE from table1 to table2, yo will just need to do first copy data to table2 (as described) and then do DELETE from table1 where table1.ID = desiredID, and at the end to refresh left grid (since you deleted slected row). When refreshing left grid, you should take decision what to do: clear grid or position to previous or next ID from table1.

regards
I'm finding this quite difficult to follow - is it possible for tou tp provide an example ?
ASKER CERTIFIED SOLUTION
Avatar of pnedic
pnedic
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can do this

dTable.DefaultView.RowFilter = "Type=1"
Dim dTemp as DataTable = dTable.DefaultView.ToTable()
Where do I put that code and how can it be used to define the filter
That depends on you app. Are you using datatables?

>1. be able to filter the left most table by location - ir I want to put a textbox/combo box on the form, enter a location and then have the dataset on the left update to show only matching records.

Then you would put the first line in the button click for filter. Or if you use combobox then you can put the first line in combobox_selectedindexchange event.

You can put the second line in > button click and assign the dTemp as datasource of second grid.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry for the delay in getting back to you - have been away from work due to SNOW!

I will try the suggestions shortly