From: Ginny Caughey [MVP] on
Mark,

Thanks for the small sample so I can see what you mean.

As Ilya says, you can only use a *new* resultset to "filter" the data. For
example if you add something like this as a form variable

SqlCeResultSet newRS;

then you can have code like this to create new resultsets that just show the
single record that matches the value entered.

SqlCeCommand cmd = categoriesResultSet.Connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select * from Categories where [Category ID] = '" +
category_IDTextBox.Text + "'";
newRS = cmd.ExecuteResultSet(ResultSetOptions.Scrollable |
ResultSetOptions.Updatable);
categoriesResultSetBindingSource.DataSource = newRS;

I'm not sure this is really what you want though as you can see if you also
add a bound DataGrid to the form.

I'd suggest using a buffer area rather than a live connection to a resultset
to get data from the user. Then you can easily check to see if the Category
ID entered already exists, in which case you can show it, or if it doesn't
in which case you can add it.


--
Ginny Caughey
..NET Compact Framework MVP


"Mark Huisinga" <mhuisinga(a)newsgroups.nospam> wrote in message
news:nJvmg.33352$UQ2.4279(a)beryl...
> categoriesResultSet is generated.(Northwind).
> categoriesResulstSet set to Detail in the Data Sources then dragged onto a
> form.
>
> call Addnew, Then type exisiting CategoryID in Category ID Text Box. Now I
> want to retrieve the corresponding record and position the BindingSource
> on the corresponding record.
>
> private void Form1_Load(object sender, EventArgs e)
> {
> categoriesResultSet = new
> DeviceApplication3.CategoriesResultsetResultSets.CategoriesResultSet();
> categoriesResultSet.Bind(this.categoriesResultSetBindingSource);
> }
>
> private void btnAddnew_Click(object sender, EventArgs e)
> {
> categoriesResultSetBindingSource.AddNew();
> }
>
> private void category_IDTextBox_LostFocus(object sender, EventArgs e)
> {
> // solution 1
> if (categoriesResultSetBindingSource.SupportsSearching == false)
> {
> // too bad, this whould have made life easy
> MessageBox.Show("No search support");
> }
>
> // solution 2
> // try seek but doesn't work
> if
> (categoriesResultSet.Seek(System.Data.SqlServerCe.DbSeekOptions.FirstEqual,
> new object[] { category_IDTextBox.Text }))
> {
> categoriesResultSet.Read();
> categoriesResultSetBindingSource.DataSource =
> categoriesResultSet.ResultSetView;
> }
>
> // solution 3
> // this also doesn't work. Presumably pass the record as parameter, but
> how to get record ?
> int index =
> categoriesResultSetBindingSource.IndexOf(category_IDTextBox.Text);
> if (index > 0)
> {
> categoriesResultSetBindingSource.Position = index;
> }
> }
>
> Hope this sheds some light on it.
>
> Mark
>
> "Ginny Caughey [MVP]" <ginny.caughey.online(a)wasteworks.com> schreef in
> bericht news:Ouv5r2elGHA.4308(a)TK2MSFTNGP05.phx.gbl...
>> Mark,
>>
>> If you have a *small* sample of code that illustrates what you're trying
>> to do I'll be glad to have a look at it. I also prefer SqlCeResultSet not
>> only for speed but also because it's generally a lot easier to use, but I
>> haven't run into the problem you're describing so I'm curious exactly
>> what you're doing.
>>
>> --
>> Ginny Caughey
>> .NET Compact Framework MVP
>>
>>
>> "Mark Huisinga" <mhuisinga(a)newsgroups.nospam> wrote in message
>> news:Farmg.32173$UQ2.12865(a)beryl...
>>> Hi Ginny,
>>>
>>> Actually there is no "new" resultset. What I'm doing is when the user
>>> enters a categoryid in the lostfocus event of the textbox I do a seek on
>>> the resultset. If a category id is found I want to update the
>>> bindingsource to the same position as the resultset.
>>>
>>> I prefer the sqlceresultset because it is faster on the device with
>>> large tables.
>>>
>>> Mark
>>>
>>> "Ginny Caughey [MVP]" <ginny.caughey.online(a)wasteworks.com> schreef in
>>> bericht news:eWgTxsVlGHA.3528(a)TK2MSFTNGP02.phx.gbl...
>>>> Mark,
>>>>
>>>> What if you just set the DataSource to the new result set? Or use a
>>>> DataTable instead of a result set?
>>>>
>>>> --
>>>> Ginny Caughey
>>>> .NET Compact Framework MVP
>>>>
>>>>
>>>> "Mark Huisinga" <mhuisinga(a)newsgroups.nospam> wrote in message
>>>> news:yefmg.23811$UQ2.22061(a)beryl...
>>>>> Ginny,
>>>>>
>>>>> I tried that, but setting the bindingresource to null resulst in an
>>>>> ArgumentException without an errormessage ( the source assembly cannot
>>>>> be found).
>>>>>
>>>>> Mark
>>>>>
>>>>> "Ginny Caughey [MVP]" <ginny.caughey.online(a)wasteworks.com> schreef in
>>>>> bericht news:%236F1$IVlGHA.3396(a)TK2MSFTNGP05.phx.gbl...
>>>>>> Mark,
>>>>>>
>>>>>> Probably the best way would be to set the BindingSource.DataSource to
>>>>>> null, then set it back to your new resultset.
>>>>>>
>>>>>> --
>>>>>> Ginny Caughey
>>>>>> .NET Compact Framework MVP
>>>>>>
>>>>>>
>>>>>> "Mark Huisinga" <mhuisinga(a)newsgroups.nospam> wrote in message
>>>>>> news:6%dmg.22179$UQ2.2647(a)beryl...
>>>>>>> Ginny,
>>>>>>>
>>>>>>> Ok, that is too bad. I have tried to achieve something similar by
>>>>>>> using the sqlceresult seek method, however I then have no idea of
>>>>>>> how to update the bindingsource so that my controls show the correct
>>>>>>> record. Is this at all possible ?
>>>>>>>
>>>>>>> thanx,
>>>>>>>
>>>>>>> Mark
>>>>>>>
>>>>>>>
>>>>>>> "Ginny Caughey [MVP]" <ginny.caughey.online(a)wasteworks.com> schreef
>>>>>>> in bericht news:u$MjhaUlGHA.3816(a)TK2MSFTNGP02.phx.gbl...
>>>>>>>> Mark,
>>>>>>>>
>>>>>>>> I think it's probably a limitation of the SqlCeResultSet since it
>>>>>>>> doesn't contain the actual data and only maintains pointers to the
>>>>>>>> data (unlike DataSet). Similarly Sort is also not supported I
>>>>>>>> believe.
>>>>>>>>
>>>>>>>> --
>>>>>>>> Ginny Caughey
>>>>>>>> .NET Compact Framework MVP
>>>>>>>>
>>>>>>>>
>>>>>>>> "Mark Huisinga" <mhuisinga(a)newsgroups.nospam> wrote in message
>>>>>>>> news:_Tcmg.19470$UQ2.9875(a)beryl...
>>>>>>>>> Bindingsource.find(..) doesn't seem to work on a bindingsource
>>>>>>>>> with as datasource a sqlceresultset.resultview. As far as I can
>>>>>>>>> tell this is odd since the sqlceresultset.resultview does
>>>>>>>>> implement IBindingList. Or is this a limitation of the
>>>>>>>>> compactframework ?
>>>>>>>>>
>>>>>>>>> Mark.
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>


From: Mark Huisinga on
Ok,

then I'll skip the binding and just use the resultset. If I manually fill my
controls I'll be more flexible (It is more work, but ok).

thanx for your time, and Ilya's.

Mark

"Ginny Caughey [MVP]" <ginny.caughey.online(a)wasteworks.com> schreef in
bericht news:e7wC3yjlGHA.1640(a)TK2MSFTNGP02.phx.gbl...
> Mark,
>
> Thanks for the small sample so I can see what you mean.
>
> As Ilya says, you can only use a *new* resultset to "filter" the data. For
> example if you add something like this as a form variable
>
> SqlCeResultSet newRS;
>
> then you can have code like this to create new resultsets that just show
> the single record that matches the value entered.
>
> SqlCeCommand cmd = categoriesResultSet.Connection.CreateCommand();
> cmd.CommandType = CommandType.Text;
> cmd.CommandText = "Select * from Categories where [Category ID] = '" +
> category_IDTextBox.Text + "'";
> newRS = cmd.ExecuteResultSet(ResultSetOptions.Scrollable |
> ResultSetOptions.Updatable);
> categoriesResultSetBindingSource.DataSource = newRS;
>
> I'm not sure this is really what you want though as you can see if you
> also add a bound DataGrid to the form.
>
> I'd suggest using a buffer area rather than a live connection to a
> resultset to get data from the user. Then you can easily check to see if
> the Category ID entered already exists, in which case you can show it, or
> if it doesn't in which case you can add it.
>
>
> --
> Ginny Caughey
> .NET Compact Framework MVP
>
>
> "Mark Huisinga" <mhuisinga(a)newsgroups.nospam> wrote in message
> news:nJvmg.33352$UQ2.4279(a)beryl...
>> categoriesResultSet is generated.(Northwind).
>> categoriesResulstSet set to Detail in the Data Sources then dragged onto
>> a form.
>>
>> call Addnew, Then type exisiting CategoryID in Category ID Text Box. Now
>> I want to retrieve the corresponding record and position the
>> BindingSource on the corresponding record.
>>
>> private void Form1_Load(object sender, EventArgs e)
>> {
>> categoriesResultSet = new
>> DeviceApplication3.CategoriesResultsetResultSets.CategoriesResultSet();
>> categoriesResultSet.Bind(this.categoriesResultSetBindingSource);
>> }
>>
>> private void btnAddnew_Click(object sender, EventArgs e)
>> {
>> categoriesResultSetBindingSource.AddNew();
>> }
>>
>> private void category_IDTextBox_LostFocus(object sender, EventArgs e)
>> {
>> // solution 1
>> if (categoriesResultSetBindingSource.SupportsSearching == false)
>> {
>> // too bad, this whould have made life easy
>> MessageBox.Show("No search support");
>> }
>>
>> // solution 2
>> // try seek but doesn't work
>> if
>> (categoriesResultSet.Seek(System.Data.SqlServerCe.DbSeekOptions.FirstEqual,
>> new object[] { category_IDTextBox.Text }))
>> {
>> categoriesResultSet.Read();
>> categoriesResultSetBindingSource.DataSource =
>> categoriesResultSet.ResultSetView;
>> }
>>
>> // solution 3
>> // this also doesn't work. Presumably pass the record as parameter,
>> but how to get record ?
>> int index =
>> categoriesResultSetBindingSource.IndexOf(category_IDTextBox.Text);
>> if (index > 0)
>> {
>> categoriesResultSetBindingSource.Position = index;
>> }
>> }
>>
>> Hope this sheds some light on it.
>>
>> Mark
>>
>> "Ginny Caughey [MVP]" <ginny.caughey.online(a)wasteworks.com> schreef in
>> bericht news:Ouv5r2elGHA.4308(a)TK2MSFTNGP05.phx.gbl...
>>> Mark,
>>>
>>> If you have a *small* sample of code that illustrates what you're trying
>>> to do I'll be glad to have a look at it. I also prefer SqlCeResultSet
>>> not only for speed but also because it's generally a lot easier to use,
>>> but I haven't run into the problem you're describing so I'm curious
>>> exactly what you're doing.
>>>
>>> --
>>> Ginny Caughey
>>> .NET Compact Framework MVP
>>>
>>>
>>> "Mark Huisinga" <mhuisinga(a)newsgroups.nospam> wrote in message
>>> news:Farmg.32173$UQ2.12865(a)beryl...
>>>> Hi Ginny,
>>>>
>>>> Actually there is no "new" resultset. What I'm doing is when the user
>>>> enters a categoryid in the lostfocus event of the textbox I do a seek
>>>> on the resultset. If a category id is found I want to update the
>>>> bindingsource to the same position as the resultset.
>>>>
>>>> I prefer the sqlceresultset because it is faster on the device with
>>>> large tables.
>>>>
>>>> Mark
>>>>
>>>> "Ginny Caughey [MVP]" <ginny.caughey.online(a)wasteworks.com> schreef in
>>>> bericht news:eWgTxsVlGHA.3528(a)TK2MSFTNGP02.phx.gbl...
>>>>> Mark,
>>>>>
>>>>> What if you just set the DataSource to the new result set? Or use a
>>>>> DataTable instead of a result set?
>>>>>
>>>>> --
>>>>> Ginny Caughey
>>>>> .NET Compact Framework MVP
>>>>>
>>>>>
>>>>> "Mark Huisinga" <mhuisinga(a)newsgroups.nospam> wrote in message
>>>>> news:yefmg.23811$UQ2.22061(a)beryl...
>>>>>> Ginny,
>>>>>>
>>>>>> I tried that, but setting the bindingresource to null resulst in an
>>>>>> ArgumentException without an errormessage ( the source assembly
>>>>>> cannot be found).
>>>>>>
>>>>>> Mark
>>>>>>
>>>>>> "Ginny Caughey [MVP]" <ginny.caughey.online(a)wasteworks.com> schreef
>>>>>> in bericht news:%236F1$IVlGHA.3396(a)TK2MSFTNGP05.phx.gbl...
>>>>>>> Mark,
>>>>>>>
>>>>>>> Probably the best way would be to set the BindingSource.DataSource
>>>>>>> to null, then set it back to your new resultset.
>>>>>>>
>>>>>>> --
>>>>>>> Ginny Caughey
>>>>>>> .NET Compact Framework MVP
>>>>>>>
>>>>>>>
>>>>>>> "Mark Huisinga" <mhuisinga(a)newsgroups.nospam> wrote in message
>>>>>>> news:6%dmg.22179$UQ2.2647(a)beryl...
>>>>>>>> Ginny,
>>>>>>>>
>>>>>>>> Ok, that is too bad. I have tried to achieve something similar by
>>>>>>>> using the sqlceresult seek method, however I then have no idea of
>>>>>>>> how to update the bindingsource so that my controls show the
>>>>>>>> correct record. Is this at all possible ?
>>>>>>>>
>>>>>>>> thanx,
>>>>>>>>
>>>>>>>> Mark
>>>>>>>>
>>>>>>>>
>>>>>>>> "Ginny Caughey [MVP]" <ginny.caughey.online(a)wasteworks.com> schreef
>>>>>>>> in bericht news:u$MjhaUlGHA.3816(a)TK2MSFTNGP02.phx.gbl...
>>>>>>>>> Mark,
>>>>>>>>>
>>>>>>>>> I think it's probably a limitation of the SqlCeResultSet since it
>>>>>>>>> doesn't contain the actual data and only maintains pointers to the
>>>>>>>>> data (unlike DataSet). Similarly Sort is also not supported I
>>>>>>>>> believe.
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Ginny Caughey
>>>>>>>>> .NET Compact Framework MVP
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> "Mark Huisinga" <mhuisinga(a)newsgroups.nospam> wrote in message
>>>>>>>>> news:_Tcmg.19470$UQ2.9875(a)beryl...
>>>>>>>>>> Bindingsource.find(..) doesn't seem to work on a bindingsource
>>>>>>>>>> with as datasource a sqlceresultset.resultview. As far as I can
>>>>>>>>>> tell this is odd since the sqlceresultset.resultview does
>>>>>>>>>> implement IBindingList. Or is this a limitation of the
>>>>>>>>>> compactframework ?
>>>>>>>>>>
>>>>>>>>>> Mark.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>