RobR
September 14th, 2011, 03:18 PM
Greetings!
I am playing with strongly typed data sets created using the MS VS 2008 Database Designerm, in a project targeting .Net 2.0. I successfully got it to update the first row in my data table. I ran the program again and expected the first row to be updated again. It wasn't. The second row was updated. I realized that the problem was that I was not specifying a sort order. I don't have the opportunity to call my data table's Select() method, which takes an argument specifying the sort order, because that's somewhere behind the scenes.
So, after poking around on the Internet, I learned that I can set the table's DefaultView's Sort property. I tried that, but got the same result. Here's the code I have now:
CraneDataSet craneData = new CraneDataSet();
CraneDataSetTableAdapters.craneTableAdapter cta = new craneTableAdapter();
CraneDataSet.craneDataTable cdt = (CraneDataSet.craneDataTable)craneData.Tables["crane"];
cdt.DefaultView.Sort = "crane_identification ASC";
cta.Fill(cdt);
CraneDataSet.craneRow cRow = (CraneDataSet.craneRow)cdt.Rows[0];
cRow.x_coordinate *= 10;
cta.Update(cRow);
In a thread in the Visual Basic forum, someone was asking about sorting data for display in a listbox. In that thread, someone said:
"No, the player won't match the index in the DataTable, but it WILL match the index in the DefaultView. You can't sort a DataTable and don't give it another thought because there's no need. If you've bound your DataTable to the ListBox then what you see in the ListBox is the data in the DeafultView. If you sort and/or filter the DefaultView then the data in the ListBox will reflect this. When the user selects an item in the ListBox the SelectedIndex can be used to get the corresponding DataRowView from the table's DefaultView. You can do most of what you need to with that DataRowView object but, if you really need a DataRow for some reason, you can get it from the Row property. "
According to that, setting the DefaultView object's Sort property wouldn't have any effect for me, either, since I'm getting data from the table, not the view. But the view doesn't have a Rows collection or any way I see to get data out of it. So, how do I make sure that it is always the first record in my table that gets changed when I update my first row?
Thanks very much!
RobR
I am playing with strongly typed data sets created using the MS VS 2008 Database Designerm, in a project targeting .Net 2.0. I successfully got it to update the first row in my data table. I ran the program again and expected the first row to be updated again. It wasn't. The second row was updated. I realized that the problem was that I was not specifying a sort order. I don't have the opportunity to call my data table's Select() method, which takes an argument specifying the sort order, because that's somewhere behind the scenes.
So, after poking around on the Internet, I learned that I can set the table's DefaultView's Sort property. I tried that, but got the same result. Here's the code I have now:
CraneDataSet craneData = new CraneDataSet();
CraneDataSetTableAdapters.craneTableAdapter cta = new craneTableAdapter();
CraneDataSet.craneDataTable cdt = (CraneDataSet.craneDataTable)craneData.Tables["crane"];
cdt.DefaultView.Sort = "crane_identification ASC";
cta.Fill(cdt);
CraneDataSet.craneRow cRow = (CraneDataSet.craneRow)cdt.Rows[0];
cRow.x_coordinate *= 10;
cta.Update(cRow);
In a thread in the Visual Basic forum, someone was asking about sorting data for display in a listbox. In that thread, someone said:
"No, the player won't match the index in the DataTable, but it WILL match the index in the DefaultView. You can't sort a DataTable and don't give it another thought because there's no need. If you've bound your DataTable to the ListBox then what you see in the ListBox is the data in the DeafultView. If you sort and/or filter the DefaultView then the data in the ListBox will reflect this. When the user selects an item in the ListBox the SelectedIndex can be used to get the corresponding DataRowView from the table's DefaultView. You can do most of what you need to with that DataRowView object but, if you really need a DataRow for some reason, you can get it from the Row property. "
According to that, setting the DefaultView object's Sort property wouldn't have any effect for me, either, since I'm getting data from the table, not the view. But the view doesn't have a Rows collection or any way I see to get data out of it. So, how do I make sure that it is always the first record in my table that gets changed when I update my first row?
Thanks very much!
RobR