hemenkap Posted March 6, 2003 Posted March 6, 2003 hi friends, i have been programming with dataset since 2 weeks, well i do know that dataset does not support a cursor like the recordset so we cannot get the current position in the recordset. however i have created an user control for handling the navigation of the dataset as well as to handle saving of form data plus othe functions also. in that control i am passing the dataset as well as the table name in the dataset to navigate and the navigation works just fine. i am even able to retrive my current position in the dataset using my control ( however this works only if you are navigating thru the database using the navigation buttons provided). now waht i am trying to do is that when the user enters some data in a field on the form. on each key press event i check if the textbox.TEXT matches with any of the rows in a particular column in the database. if NO MATCH means that the user may be entering a new record and form enters INSERT MODE, if there is a match the all the remaing textboxes are filled to diaplay the data for that recoed and the form enters EDIT MODE. however when this happens what i want to do is that i want to update my navigation control so that it displays my current position in the dataset.. i am locatin the current row using the dataset.tables.Select method as i am not searchin on primary key. my navigation control uses me.parentform.bindingcontext(dataset.tables).posotion to locate my current position in the dataset.... if onyl you can tell me that once i do a Select/Find using the textbox.Text string AND if i hit a row ( it will always return one row only as the string is unique ) how to know the position of this row. As both these method return a row/ or row collection. but i am not intrested much in the row returned. it is the position that is outmost important... if any body can help it will be truly great thanks. Hemen Quote
*Experts* Nerseus Posted March 6, 2003 *Experts* Posted March 6, 2003 You have two options. Loop through the DataSet one row at a time (using a "for i =..." type of loop) and compare the value manually. When (and if) a match is found, you have your row number. The other method uses a DataView. You can use the DataView's Find method (similar to Select) but returns a row index. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
hemenkap Posted March 7, 2003 Author Posted March 7, 2003 ok thanks, i dont think looping is a good option as there could be more than 5000 records and looping is tedious. i will try the dataviews find method and see if this works. will surely tell if it worked or now. thanks once againg for help... Hemen Kapadia Quote
hemenkap Posted March 10, 2003 Author Posted March 10, 2003 Hi Nerseus, thanks for replying. i tried it out. but did not help.... can you think of any other way..... Hemen Quote
jc3 Posted April 14, 2003 Posted April 14, 2003 Hi To find current record, you must use BindingManagerBase object ( More information about ) For example: 'ds1 - DataSet 'Example - name of the DataSet's table 'idRow - name of the keycolumn Dim bm As BindingManagerBase bm = Me.BindingContext.Item(ds1, "Example") Dim dr As DataRowView = CType(bm.Current, DataRowView) 'you must cast Current object to corret type MessageBox.Show(CType(dr.Item("idRow"), String)) -- I was writing this example without VS Editor. Get a reply how it working PS. Sorry for grammar - my english is very poor :( jc3 Quote
hemenkap Posted April 15, 2003 Author Posted April 15, 2003 thanks, but dr.Item("IDRow") will return the data stored in the colum called idRow in the database. it dont want that . it want the position of the datarow in the dataset. what i need is this, i am explaining it in terms of recordset. as it might make things clear. when we do recordset.Find ( SOME CRITERIA ) the the recordset is searched for all rows and it stops at the row which satisfies our condition. moves to current row pointer to that row. now since in a dataset there is nothing like the current row pointer ( this is the reason we do not have anything like Move last, move first etc...) . i treied a lot will try this too. if it works i will let you know bye, hemen Kapadia Quote
joyin Posted May 12, 2003 Posted May 12, 2003 (edited) I too am stuck with the same problem in Vb.net. Can someone please guide as to how one can get the position of a datarow in a dataset? Any help will be greatly appreciated.:confused: Edited May 12, 2003 by joyin Quote
hemenkap Posted May 14, 2003 Author Posted May 14, 2003 hi friends, finally after about 2 months this problem is solved. you can do the following as i do it. the commandtext of my select command looks like this. SELECT * FROM TABLE ORDER BY COLUMN_YOU_WANT_TO_SEARCH_ON the column on which i order is the customer code ( for example) which i have ket unique and is indexed as i dont want to repeat codes the primary key is and integer column hidden from the user of the system. now once you have filled a table in the dataset you have to create a dataview from this table using the ORDER BY column to sort it. The dataview.Find method returns an index ( long ) of the position of the current datarow in the sorted dataset rather than the actual datarow as returned by most other find methods. this is the only way i could do it. if anybody knows any better way do let me know. i dont remember the actual dataview code. it is very small about 3 to 4 lines you can see it in MSDN Hemen Kapadia Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.