Bindingsource Find method

  • Thread starter Thread starter Mark Huisinga
  • Start date Start date
M

Mark Huisinga

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.
 
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,

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
 
Mark,

Probably the best way would be to set the BindingSource.DataSource to null,
then set it back to your new resultset.
 
Ginny,

I tried that, but setting the bindingresource to null resulst in an
ArgumentException without an errormessage ( the source assembly cannot be
found).

Mark
 
Mark,

What if you just set the DataSource to the new result set? Or use a
DataTable instead of a result set?
 
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
 
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.
 
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
 
RS does not have any data inside, so you can not use Find(), IndexOf() and
so on - there's no data to find or compare against.

The idea of RS is what if you need to find something, SQL Mobile should do
that. So please construct another SQL query and execute new RS.



If that does not fit your pattern, please use DataSet which loads all the
data to allow for Find().


--
Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).

Mark Huisinga said:
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 said:
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.
 
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 said:
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 said:
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.
 
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 said:
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 said:
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 said:
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


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]" <[email protected]> schreef in
bericht 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


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]" <[email protected]> schreef
in bericht 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


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]" <[email protected]> schreef
in bericht 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


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.
 
Back
Top