|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Addign a row to a datasetVS2003 C#
Hi, My dataset is ordered. When I add another row to it by creating a new row then using AddNew(), & then persisting it to the underlying table, thencaccepting changes to the dataset, the new row is appended to the datasets datatable, but not ordered. How can I add it to the table but have it placed in the order it should be in (particular row Ascending, for example.)? Currently I need to end & reload the application for the dataset to be rebuilt in the correct order. Any ideas would be most appreciated. ant Firstly, if you really want to add a new DataRow into a DataTable in
particular order, you can use DataTable.Rows.InsertAt(), instead of DataTable.Rows.Add(); Secondly, AcceptChanges() has nothing to do with order here; Thirdly, there is almost no need to bother DataRow's order in DataTable. You can use DataView (created on top of DataTable, or the DataTable's default DataView) to sort the DataTable whatever way you want to. Show quote "Ant" <A**@discussions.microsoft.com> wrote in message news:C207095C-4243-4970-90A2-5C3B2073E174@microsoft.com... > VS2003 C# > Hi, > > My dataset is ordered. When I add another row to it by creating a new row > then using AddNew(), & then persisting it to the underlying table, > thencaccepting changes to the dataset, the new row is appended to the > datasets datatable, but not ordered. > > How can I add it to the table but have it placed in the order it should be > in (particular row Ascending, for example.)? > > Currently I need to end & reload the application for the dataset to be > rebuilt in the correct order. > > Any ideas would be most appreciated. > > ant Hello Norman,
Thank you for your tips. I am in fact working with a dataview, however this doesn't seem to fix the problem. I use the code below to create a fresh data view each time a user triggers the textcanged event of the text box as below: string filter = "companyName LIKE '" + txtsearch.Text + "%'"; DataView dvFind = new DataView(dsMain.contact); dvFind.RowFilter = filter; lstFind.DataSource = dvFind; lstFind.DisplayMember = "companyName"; This is used to populate a list box with company names derived from the filter, however, the indexes seem to be offset with each new insert. why is this so? Thanks for any help Ant Show quote "Norman Yuan" wrote: > Firstly, if you really want to add a new DataRow into a DataTable in > particular order, you can use DataTable.Rows.InsertAt(), instead of > DataTable.Rows.Add(); > > Secondly, AcceptChanges() has nothing to do with order here; > > Thirdly, there is almost no need to bother DataRow's order in DataTable. You > can use DataView (created on top of DataTable, or the DataTable's default > DataView) to sort the DataTable whatever way you want to. > > "Ant" <A**@discussions.microsoft.com> wrote in message > news:C207095C-4243-4970-90A2-5C3B2073E174@microsoft.com... > > VS2003 C# > > Hi, > > > > My dataset is ordered. When I add another row to it by creating a new row > > then using AddNew(), & then persisting it to the underlying table, > > thencaccepting changes to the dataset, the new row is appended to the > > datasets datatable, but not ordered. > > > > How can I add it to the table but have it placed in the order it should be > > in (particular row Ascending, for example.)? > > > > Currently I need to end & reload the application for the dataset to be > > rebuilt in the correct order. > > > > Any ideas would be most appreciated. > > > > ant > > > Look into using the "Sort" method of your View object, like so:
dvFind.RowFilter = filter; dvFind.Sort="State, ZipCode DESC" lstFind.DataSource = dvFind; lstFind.DisplayMember = "companyName"; Of course, replace State and Zipcode with your real column names. HTH Ant wrote: Show quote > Hello Norman, > > Thank you for your tips. > > I am in fact working with a dataview, however this doesn't seem to fix the > problem. > > > I use the code below to create a fresh data view each time a user triggers > the textcanged event of the text box as below: > > > string filter = "companyName LIKE '" + txtsearch.Text + "%'"; > DataView dvFind = new DataView(dsMain.contact); > > dvFind.RowFilter = filter; > lstFind.DataSource = dvFind; > lstFind.DisplayMember = "companyName"; > > This is used to populate a list box with company names derived from the > filter, however, the indexes seem to be offset with each new insert. > > why is this so? > > Thanks for any help > > Ant > > "Norman Yuan" wrote: > > > Firstly, if you really want to add a new DataRow into a DataTable in > > particular order, you can use DataTable.Rows.InsertAt(), instead of > > DataTable.Rows.Add(); > > > > Secondly, AcceptChanges() has nothing to do with order here; > > > > Thirdly, there is almost no need to bother DataRow's order in DataTable. You > > can use DataView (created on top of DataTable, or the DataTable's default > > DataView) to sort the DataTable whatever way you want to. > > > > "Ant" <A**@discussions.microsoft.com> wrote in message > > news:C207095C-4243-4970-90A2-5C3B2073E174@microsoft.com... > > > VS2003 C# > > > Hi, > > > > > > My dataset is ordered. When I add another row to it by creating a new row > > > then using AddNew(), & then persisting it to the underlying table, > > > thencaccepting changes to the dataset, the new row is appended to the > > > datasets datatable, but not ordered. > > > > > > How can I add it to the table but have it placed in the order it should be > > > in (particular row Ascending, for example.)? > > > > > > Currently I need to end & reload the application for the dataset to be > > > rebuilt in the correct order. > > > > > > Any ideas would be most appreciated. > > > > > > ant > > > > > > Thanks all. esp. Jerry. This gets me closer to working this out.
Cheers Ant Show quote "Jerry H." wrote: > Look into using the "Sort" method of your View object, like so: > > dvFind.RowFilter = filter; > dvFind.Sort="State, ZipCode DESC" > lstFind.DataSource = dvFind; > lstFind.DisplayMember = "companyName"; > > Of course, replace State and Zipcode with your real column names. > > HTH > > Ant wrote: > > Hello Norman, > > > > Thank you for your tips. > > > > I am in fact working with a dataview, however this doesn't seem to fix the > > problem. > > > > > > I use the code below to create a fresh data view each time a user triggers > > the textcanged event of the text box as below: > > > > > > string filter = "companyName LIKE '" + txtsearch.Text + "%'"; > > DataView dvFind = new DataView(dsMain.contact); > > > > dvFind.RowFilter = filter; > > lstFind.DataSource = dvFind; > > lstFind.DisplayMember = "companyName"; > > > > This is used to populate a list box with company names derived from the > > filter, however, the indexes seem to be offset with each new insert. > > > > why is this so? > > > > Thanks for any help > > > > Ant > > > > "Norman Yuan" wrote: > > > > > Firstly, if you really want to add a new DataRow into a DataTable in > > > particular order, you can use DataTable.Rows.InsertAt(), instead of > > > DataTable.Rows.Add(); > > > > > > Secondly, AcceptChanges() has nothing to do with order here; > > > > > > Thirdly, there is almost no need to bother DataRow's order in DataTable. You > > > can use DataView (created on top of DataTable, or the DataTable's default > > > DataView) to sort the DataTable whatever way you want to. > > > > > > "Ant" <A**@discussions.microsoft.com> wrote in message > > > news:C207095C-4243-4970-90A2-5C3B2073E174@microsoft.com... > > > > VS2003 C# > > > > Hi, > > > > > > > > My dataset is ordered. When I add another row to it by creating a new row > > > > then using AddNew(), & then persisting it to the underlying table, > > > > thencaccepting changes to the dataset, the new row is appended to the > > > > datasets datatable, but not ordered. > > > > > > > > How can I add it to the table but have it placed in the order it should be > > > > in (particular row Ascending, for example.)? > > > > > > > > Currently I need to end & reload the application for the dataset to be > > > > rebuilt in the correct order. > > > > > > > > Any ideas would be most appreciated. > > > > > > > > ant > > > > > > > > > > > Ant,
As the others wrote already, There is in fact no reason to get a dataset in a real sequence. However there can be one reason that is if you serialize your dataset and want to access it in a sequential way. Than there is now the new overloaded DataView.ToTable method. http://msdn2.microsoft.com/en-us/library/a8ycds2f.aspx I hope this helps, Cor Show quote "Ant" <A**@discussions.microsoft.com> schreef in bericht news:68839F0C-5E43-4C91-8496-64CFAFD1A3FC@microsoft.com... > Thanks all. esp. Jerry. This gets me closer to working this out. > > Cheers > Ant > > "Jerry H." wrote: > >> Look into using the "Sort" method of your View object, like so: >> >> dvFind.RowFilter = filter; >> dvFind.Sort="State, ZipCode DESC" >> lstFind.DataSource = dvFind; >> lstFind.DisplayMember = "companyName"; >> >> Of course, replace State and Zipcode with your real column names. >> >> HTH >> >> Ant wrote: >> > Hello Norman, >> > >> > Thank you for your tips. >> > >> > I am in fact working with a dataview, however this doesn't seem to fix >> > the >> > problem. >> > >> > >> > I use the code below to create a fresh data view each time a user >> > triggers >> > the textcanged event of the text box as below: >> > >> > >> > string filter = "companyName LIKE '" + txtsearch.Text + "%'"; >> > DataView dvFind = new DataView(dsMain.contact); >> > >> > dvFind.RowFilter = filter; >> > lstFind.DataSource = dvFind; >> > lstFind.DisplayMember = "companyName"; >> > >> > This is used to populate a list box with company names derived from the >> > filter, however, the indexes seem to be offset with each new insert. >> > >> > why is this so? >> > >> > Thanks for any help >> > >> > Ant >> > >> > "Norman Yuan" wrote: >> > >> > > Firstly, if you really want to add a new DataRow into a DataTable in >> > > particular order, you can use DataTable.Rows.InsertAt(), instead of >> > > DataTable.Rows.Add(); >> > > >> > > Secondly, AcceptChanges() has nothing to do with order here; >> > > >> > > Thirdly, there is almost no need to bother DataRow's order in >> > > DataTable. You >> > > can use DataView (created on top of DataTable, or the DataTable's >> > > default >> > > DataView) to sort the DataTable whatever way you want to. >> > > >> > > "Ant" <A**@discussions.microsoft.com> wrote in message >> > > news:C207095C-4243-4970-90A2-5C3B2073E174@microsoft.com... >> > > > VS2003 C# >> > > > Hi, >> > > > >> > > > My dataset is ordered. When I add another row to it by creating a >> > > > new row >> > > > then using AddNew(), & then persisting it to the underlying table, >> > > > thencaccepting changes to the dataset, the new row is appended to >> > > > the >> > > > datasets datatable, but not ordered. >> > > > >> > > > How can I add it to the table but have it placed in the order it >> > > > should be >> > > > in (particular row Ascending, for example.)? >> > > > >> > > > Currently I need to end & reload the application for the dataset to >> > > > be >> > > > rebuilt in the correct order. >> > > > >> > > > Any ideas would be most appreciated. >> > > > >> > > > ant >> > > >> > > >> > > >> >> Hi Cor,
Thanks for the input. Are you suggesting the best way to do this would be to bind a Dataview to the controls instead of a Dataset? Ccurrently I have a typed dataset bound to the testbox controls. I then use a dataview to filter the 'user choice'. How would this be best done? Thanks for any ideas Ant Show quote "Cor Ligthert [MVP]" wrote: > Ant, > > As the others wrote already, There is in fact no reason to get a dataset in > a real sequence. However there can be one reason that is if you serialize > your dataset and want to access it in a sequential way. > > Than there is now the new overloaded DataView.ToTable method. > > http://msdn2.microsoft.com/en-us/library/a8ycds2f.aspx > > I hope this helps, > > Cor > > "Ant" <A**@discussions.microsoft.com> schreef in bericht > news:68839F0C-5E43-4C91-8496-64CFAFD1A3FC@microsoft.com... > > Thanks all. esp. Jerry. This gets me closer to working this out. > > > > Cheers > > Ant > > > > "Jerry H." wrote: > > > >> Look into using the "Sort" method of your View object, like so: > >> > >> dvFind.RowFilter = filter; > >> dvFind.Sort="State, ZipCode DESC" > >> lstFind.DataSource = dvFind; > >> lstFind.DisplayMember = "companyName"; > >> > >> Of course, replace State and Zipcode with your real column names. > >> > >> HTH > >> > >> Ant wrote: > >> > Hello Norman, > >> > > >> > Thank you for your tips. > >> > > >> > I am in fact working with a dataview, however this doesn't seem to fix > >> > the > >> > problem. > >> > > >> > > >> > I use the code below to create a fresh data view each time a user > >> > triggers > >> > the textcanged event of the text box as below: > >> > > >> > > >> > string filter = "companyName LIKE '" + txtsearch.Text + "%'"; > >> > DataView dvFind = new DataView(dsMain.contact); > >> > > >> > dvFind.RowFilter = filter; > >> > lstFind.DataSource = dvFind; > >> > lstFind.DisplayMember = "companyName"; > >> > > >> > This is used to populate a list box with company names derived from the > >> > filter, however, the indexes seem to be offset with each new insert. > >> > > >> > why is this so? > >> > > >> > Thanks for any help > >> > > >> > Ant > >> > > >> > "Norman Yuan" wrote: > >> > > >> > > Firstly, if you really want to add a new DataRow into a DataTable in > >> > > particular order, you can use DataTable.Rows.InsertAt(), instead of > >> > > DataTable.Rows.Add(); > >> > > > >> > > Secondly, AcceptChanges() has nothing to do with order here; > >> > > > >> > > Thirdly, there is almost no need to bother DataRow's order in > >> > > DataTable. You > >> > > can use DataView (created on top of DataTable, or the DataTable's > >> > > default > >> > > DataView) to sort the DataTable whatever way you want to. > >> > > > >> > > "Ant" <A**@discussions.microsoft.com> wrote in message > >> > > news:C207095C-4243-4970-90A2-5C3B2073E174@microsoft.com... > >> > > > VS2003 C# > >> > > > Hi, > >> > > > > >> > > > My dataset is ordered. When I add another row to it by creating a > >> > > > new row > >> > > > then using AddNew(), & then persisting it to the underlying table, > >> > > > thencaccepting changes to the dataset, the new row is appended to > >> > > > the > >> > > > datasets datatable, but not ordered. > >> > > > > >> > > > How can I add it to the table but have it placed in the order it > >> > > > should be > >> > > > in (particular row Ascending, for example.)? > >> > > > > >> > > > Currently I need to end & reload the application for the dataset to > >> > > > be > >> > > > rebuilt in the correct order. > >> > > > > >> > > > Any ideas would be most appreciated. > >> > > > > >> > > > ant > >> > > > >> > > > >> > > > >> > >> > > > Ant,
A dataview is a part of a datatable which are part of datasets. Mostly it is better to use a dataview (or defaultview as it is intern in the datatable) than direct a datatable. A dataset you can only bind to a DataGrid for the rest the standard Microsoft controls accept only datatables or dataviews (or other collection/lists) Cor Show quote "Ant" <A**@discussions.microsoft.com> schreef in bericht news:04A69CA8-A144-4EB4-AA2E-8357E6284898@microsoft.com... > Hi Cor, > > Thanks for the input. > > Are you suggesting the best way to do this would be to bind a Dataview to > the controls instead of a Dataset? > > Ccurrently I have a typed dataset bound to the testbox controls. I then > use > a dataview to filter the 'user choice'. > > How would this be best done? > > Thanks for any ideas > Ant > > > > "Cor Ligthert [MVP]" wrote: > >> Ant, >> >> As the others wrote already, There is in fact no reason to get a dataset >> in >> a real sequence. However there can be one reason that is if you serialize >> your dataset and want to access it in a sequential way. >> >> Than there is now the new overloaded DataView.ToTable method. >> >> http://msdn2.microsoft.com/en-us/library/a8ycds2f.aspx >> >> I hope this helps, >> >> Cor >> >> "Ant" <A**@discussions.microsoft.com> schreef in bericht >> news:68839F0C-5E43-4C91-8496-64CFAFD1A3FC@microsoft.com... >> > Thanks all. esp. Jerry. This gets me closer to working this out. >> > >> > Cheers >> > Ant >> > >> > "Jerry H." wrote: >> > >> >> Look into using the "Sort" method of your View object, like so: >> >> >> >> dvFind.RowFilter = filter; >> >> dvFind.Sort="State, ZipCode DESC" >> >> lstFind.DataSource = dvFind; >> >> lstFind.DisplayMember = "companyName"; >> >> >> >> Of course, replace State and Zipcode with your real column names. >> >> >> >> HTH >> >> >> >> Ant wrote: >> >> > Hello Norman, >> >> > >> >> > Thank you for your tips. >> >> > >> >> > I am in fact working with a dataview, however this doesn't seem to >> >> > fix >> >> > the >> >> > problem. >> >> > >> >> > >> >> > I use the code below to create a fresh data view each time a user >> >> > triggers >> >> > the textcanged event of the text box as below: >> >> > >> >> > >> >> > string filter = "companyName LIKE '" + txtsearch.Text + "%'"; >> >> > DataView dvFind = new DataView(dsMain.contact); >> >> > >> >> > dvFind.RowFilter = filter; >> >> > lstFind.DataSource = dvFind; >> >> > lstFind.DisplayMember = "companyName"; >> >> > >> >> > This is used to populate a list box with company names derived from >> >> > the >> >> > filter, however, the indexes seem to be offset with each new insert. >> >> > >> >> > why is this so? >> >> > >> >> > Thanks for any help >> >> > >> >> > Ant >> >> > >> >> > "Norman Yuan" wrote: >> >> > >> >> > > Firstly, if you really want to add a new DataRow into a DataTable >> >> > > in >> >> > > particular order, you can use DataTable.Rows.InsertAt(), instead >> >> > > of >> >> > > DataTable.Rows.Add(); >> >> > > >> >> > > Secondly, AcceptChanges() has nothing to do with order here; >> >> > > >> >> > > Thirdly, there is almost no need to bother DataRow's order in >> >> > > DataTable. You >> >> > > can use DataView (created on top of DataTable, or the DataTable's >> >> > > default >> >> > > DataView) to sort the DataTable whatever way you want to. >> >> > > >> >> > > "Ant" <A**@discussions.microsoft.com> wrote in message >> >> > > news:C207095C-4243-4970-90A2-5C3B2073E174@microsoft.com... >> >> > > > VS2003 C# >> >> > > > Hi, >> >> > > > >> >> > > > My dataset is ordered. When I add another row to it by creating >> >> > > > a >> >> > > > new row >> >> > > > then using AddNew(), & then persisting it to the underlying >> >> > > > table, >> >> > > > thencaccepting changes to the dataset, the new row is appended >> >> > > > to >> >> > > > the >> >> > > > datasets datatable, but not ordered. >> >> > > > >> >> > > > How can I add it to the table but have it placed in the order it >> >> > > > should be >> >> > > > in (particular row Ascending, for example.)? >> >> > > > >> >> > > > Currently I need to end & reload the application for the dataset >> >> > > > to >> >> > > > be >> >> > > > rebuilt in the correct order. >> >> > > > >> >> > > > Any ideas would be most appreciated. >> >> > > > >> >> > > > ant >> >> > > >> >> > > >> >> > > >> >> >> >> >> >> >> Thanks Cor,
Upon your recommendation I decided to set the binding context as a dataview & filter that. Everything works fine now. thanks very much for that insight. Cheers Ant Show quote "Cor Ligthert [MVP]" wrote: > Ant, > > A dataview is a part of a datatable which are part of datasets. > > Mostly it is better to use a dataview (or defaultview as it is intern in the > datatable) than direct a datatable. > > A dataset you can only bind to a DataGrid for the rest the standard > Microsoft controls accept only datatables or dataviews (or other > collection/lists) > > Cor > > "Ant" <A**@discussions.microsoft.com> schreef in bericht > news:04A69CA8-A144-4EB4-AA2E-8357E6284898@microsoft.com... > > Hi Cor, > > > > Thanks for the input. > > > > Are you suggesting the best way to do this would be to bind a Dataview to > > the controls instead of a Dataset? > > > > Ccurrently I have a typed dataset bound to the testbox controls. I then > > use > > a dataview to filter the 'user choice'. > > > > How would this be best done? > > > > Thanks for any ideas > > Ant > > > > > > > > "Cor Ligthert [MVP]" wrote: > > > >> Ant, > >> > >> As the others wrote already, There is in fact no reason to get a dataset > >> in > >> a real sequence. However there can be one reason that is if you serialize > >> your dataset and want to access it in a sequential way. > >> > >> Than there is now the new overloaded DataView.ToTable method. > >> > >> http://msdn2.microsoft.com/en-us/library/a8ycds2f.aspx > >> > >> I hope this helps, > >> > >> Cor > >> > >> "Ant" <A**@discussions.microsoft.com> schreef in bericht > >> news:68839F0C-5E43-4C91-8496-64CFAFD1A3FC@microsoft.com... > >> > Thanks all. esp. Jerry. This gets me closer to working this out. > >> > > >> > Cheers > >> > Ant > >> > > >> > "Jerry H." wrote: > >> > > >> >> Look into using the "Sort" method of your View object, like so: > >> >> > >> >> dvFind.RowFilter = filter; > >> >> dvFind.Sort="State, ZipCode DESC" > >> >> lstFind.DataSource = dvFind; > >> >> lstFind.DisplayMember = "companyName"; > >> >> > >> >> Of course, replace State and Zipcode with your real column names. > >> >> > >> >> HTH > >> >> > >> >> Ant wrote: > >> >> > Hello Norman, > >> >> > > >> >> > Thank you for your tips. > >> >> > > >> >> > I am in fact working with a dataview, however this doesn't seem to > >> >> > fix > >> >> > the > >> >> > problem. > >> >> > > >> >> > > >> >> > I use the code below to create a fresh data view each time a user > >> >> > triggers > >> >> > the textcanged event of the text box as below: > >> >> > > >> >> > > >> >> > string filter = "companyName LIKE '" + txtsearch.Text + "%'"; > >> >> > DataView dvFind = new DataView(dsMain.contact); > >> >> > > >> >> > dvFind.RowFilter = filter; > >> >> > lstFind.DataSource = dvFind; > >> >> > lstFind.DisplayMember = "companyName"; > >> >> > > >> >> > This is used to populate a list box with company names derived from > >> >> > the > >> >> > filter, however, the indexes seem to be offset with each new insert. > >> >> > > >> >> > why is this so? > >> >> > > >> >> > Thanks for any help > >> >> > > >> >> > Ant > >> >> > > >> >> > "Norman Yuan" wrote: > >> >> > > >> >> > > Firstly, if you really want to add a new DataRow into a DataTable > >> >> > > in > >> >> > > particular order, you can use DataTable.Rows.InsertAt(), instead > >> >> > > of > >> >> > > DataTable.Rows.Add(); > >> >> > > > >> >> > > Secondly, AcceptChanges() has nothing to do with order here; > >> >> > > > >> >> > > Thirdly, there is almost no need to bother DataRow's order in > >> >> > > DataTable. You > >> >> > > can use DataView (created on top of DataTable, or the DataTable's > >> >> > > default > >> >> > > DataView) to sort the DataTable whatever way you want to. > >> >> > > > >> >> > > "Ant" <A**@discussions.microsoft.com> wrote in message > >> >> > > news:C207095C-4243-4970-90A2-5C3B2073E174@microsoft.com... > >> >> > > > VS2003 C# > >> >> > > > Hi, > >> >> > > > > >> >> > > > My dataset is ordered. When I add another row to it by creating > >> >> > > > a > >> >> > > > new row > >> >> > > > then using AddNew(), & then persisting it to the underlying > >> >> > > > table, > >> >> > > > thencaccepting changes to the dataset, the new row is appended > >> >> > > > to > >> >> > > > the > >> >> > > > datasets datatable, but not ordered. > >> >> > > > > >> >> > > > How can I add it to the table but have it placed in the order it > >> >> > > > should be > >> >> > > > in (particular row Ascending, for example.)? > >> >> > > > > >> >> > > > Currently I need to end & reload the application for the dataset > >> >> > > > to > >> >> > > > be > >> >> > > > rebuilt in the correct order. > >> >> > > > > >> >> > > > Any ideas would be most appreciated. > >> >> > > > > >> >> > > > ant > >> >> > > > >> >> > > > >> >> > > > >> >> > >> >> > >> > >> > >> > > > |
|||||||||||||||||||||||