Noobish: Search mdf data WITHOUT binding to object...

  • Thread starter Thread starter Scott
  • Start date Start date
S

Scott

Ok, I've lost half a day to pounding my head against this one and I'm
sending out a distress call...

This is so simple that it's emberassing. However, VC# 2005 Express has
made things so monkey-proof that they made it hard to find out how to do
the simple things that don't have drag&drop tools.

This is the code in the sample that is being used to access an .mdb file:
********************
foreach (System.Data.DataRow theRow in ds.Tables["BackChat"].Rows)
{
if (sCommand == theRow["Command"].ToString())
{
string sResponse = theRow["Response"].ToString();
string sAction = theRow["Action1"].ToString();

if (sResponse != "")
{ ///////////// Do things here...
********************

It's out of the "BackChat" sample for SAPI5.1, if you're familiar with it.

Here are the issues (yea, I have issues! lol) :

All sorts of variants using my own dataSet are failing me. No matter what
I do, the best I can get it to return is the sting of the Row header, not
the contents of the cells themselves.

I've tried so many that I can't even remember them anymore... the brain is
cooked and it's time to take a break because I'm only going backward.

What I need to do is simply compare all the values listed in the "Command"
column to see if they match a var. As far as I know, this is best
approached with a foreach ().

NOTE: There is no graphical, clickable way to set the databinding to a
specific row because there is no control to bind it to!!! If there were
such a control involved here, I'd be long past this point by now.

Anyone with SpSharedRecoContext() experience should understand where I'm
stuck in a microsecond. If you understand how to use that, or how to find
specific entries in your .mdf based dataSet without using the graphical
tools, I'd sure appreciate your advice.

Thanks!

Scott
 
Scott said:
Here are the issues (yea, I have issues! lol) :

All sorts of variants using my own dataSet are failing me. No matter
what I do, the best I can get it to return is the sting of the Row
header, not the contents of the cells themselves.

OK, you've showed the code from a sample, but apparently that's not the code
you're using. Can you show what you're trying now? That'll definitely
help.
I've tried so many that I can't even remember them anymore... the
brain is cooked and it's time to take a break because I'm only going
backward.
What I need to do is simply compare all the values listed in the
"Command" column to see if they match a var. As far as I know, this
is best approached with a foreach ().

Take a look at DataTable.Select. It's as easy as:

foreach (DataRow dr in
theTable.Select(string.Format("Command='{0}'",sCommand)))
{
// all of the matching rows will be returned one by one
}
NOTE: There is no graphical, clickable way to set the databinding to a
specific row because there is no control to bind it to!!! If there
were such a control involved here, I'd be long past this point by now.

My recommendation: learn how to use the low(er) level classes first, then
learn how data binding fits into the picture. It's not a panacea.

HTH

-cd
 
My recommendation: learn how to use the low(er) level classes first,
then learn how data binding fits into the picture. It's not a panacea..

Oh I know. Trouble is that you have to pick an area to focus on or you get
buried in way too much information. I had looked at DataTable.Select and
started to get spun around a bit because I can't seem to find a way it
fits into my dataSet, bindingSource, bindingNavigator or my tableAdapeter.

In the vast majority of cases the drag and drop is easy... too easy in
some ways. Because then when you need to do it manually, you might not
know how. When dealing with the SAPI there are some com objects but, as
far as I know, binding them to certain fields is not as easy as it is with
text boxes.

I'm sitting here thinking that I should post some code but nothing is
close to functional so I'm not sure what to post LOL. Here's the current,
broken, version:

********************

private void testDbRetrieval()
{
//This string is the first entry in "Commands"
string sCommands = "Sabine, are you there?";

// *** BROKEN*** Command to look for the string above...
foreach (DataRow dr in
sabineCommandsDataGridView.Select(string.Format("Command='{0}'" ,
sCommands)))

{
// *** BROKEN*** Set string resp equal to the value of the
"Response" row at the correct index...
string resp =
sabineCommandsDataGridView.Select(String.Format("Response='{0}'"));

// Say the appropriate response for the given Command
voice.Speak(resp,SpeechVoiceSpeakFlags.SVSFDefault);
}

}

*******************

Thanks for the assistance! I understand TTS no problem and how various
contexts need to be in a tree once things get complex. I also understand
about turning off the adaptation for a command app and why it's necessary
to prevent degredation... it's the occasional, painfully simple,
fundamentals that knock me on my backside!!!

Scott
 
Scott,
from what you've posted it looks like you may be confusing the
DataGridView
Select method(which selects a "Row") with the DataTable.Select method,
which
is more of a Sql - type "filter" statement. Carl's advice was appropriate
IMHO.
Peter

Thanks Peter,

That's probably true... and it would explain a lot of my frustration. I'm
not sure that I set this one up to take SQL commands but the app is in
it's infancy and it won't take much at all to restart the project, make
sure that the db is set up right to begin with and then get back to this
point again. I figure i could have it done in half an hour or so at most.

Thanks! I'm porting myself over to VC# from Macromedia's AS1, a little
C++ and a strange mix of XML and RPN stack commands used in MS Flight
SImulator programming. I'm hoping to settle in with VC# and the custom
coding needed for Flight Sim so I can actually begin to add depth to my
knowledge... I have too much breadth as it is.

Scott
 
Scott said:
That's probably true... and it would explain a lot of my frustration. I'm
not sure that I set this one up to take SQL commands but the app is in
it's infancy and it won't take much at all to restart the project, make
sure that the db is set up right to begin with and then get back to this
point again. I figure i could have it done in half an hour or so at most.

You don't need to do anything to get SQL-like queries: the DataSet classes
do it all for you. Also, to access the elements of the row, you don't need
to use another Select, just use the indexer on DataRow:

foreach (DataRow dr in theTable.Select(
string.Format("Command='{0}'",sCommand)))
{
string resp = dr["Response"].ToString();

// Say the appropriate response for the given Command
voice.Speak(resp,SpeechVoiceSpeakFlags.SVSFDefault);
}


-cd
 
On Sun, 30 Jul 2006 20:58:11 -0400, Carl Daniel [VC++ MVP]

Carl,

Thanks a lot! I can follow your logic perfectly through this because I've
been fussing with similar methods all day. My only sticking point is that
your code states:

"...(DataRow dr in theTable.Select(..."

My confusion is with "theTable".Select()

In order to avoid.... ummm, what we used to call an "Addressing" problem
in AS1 (confusion regarding what object is being addressed), I either need
to create an instance called theTable or I need to find the appropriate
equivalent(sp?) in my existing dataSet.

The rest of it I follow perfectly... it's just that I can't seem to wrap
my head around what "theTable" is addressing... do you mean to literally
use "theTable" and create an instance of the dataTable class with that
name or did you intend for me to substitue something else in place of it
as in "myTable.Select()"?

Thanks!

Scott
Scott said:
That's probably true... and it would explain a lot of my frustration.
I'm
not sure that I set this one up to take SQL commands but the app is in
it's infancy and it won't take much at all to restart the project, make
sure that the db is set up right to begin with and then get back to this
point again. I figure i could have it done in half an hour or so at
most.

You don't need to do anything to get SQL-like queries: the DataSet
classes
do it all for you. Also, to access the elements of the row, you don't
need
to use another Select, just use the indexer on DataRow:

foreach (DataRow dr in theTable.Select(
string.Format("Command='{0}'",sCommand)))
{
string resp = dr["Response"].ToString();

// Say the appropriate response for the given Command
voice.Speak(resp,SpeechVoiceSpeakFlags.SVSFDefault);
}


-cd
 
Found it....

Syntax example is:

private void GetRows()
{
// Get the DataTable of a DataSet.
DataTable table = DataSet1.Tables["Suppliers"];
DataRow[] rows = table.Select();

// Print the value one column of each DataRow.
for(int i = 0; i < rows.Length ; i++)
{
Console.WriteLine(rows["CompanyName"]);
}
}

From:
http://msdn2.microsoft.com/en-us/library/h71xaeh0.aspx

Thanks for pointing me in the right direction!

Scott
 
Found it Patr II:

After I was positive that the code was right, it still didn't return
anything. No error, no warning, no data, no nothing....

So I played "chase the breakpoint" for a little while....

You know, it really helps to call ...TableAdapter.Fill() *BEFORE* you try
to iterate through the data in a dataset.

DOH!!!!!

Sorry about that,

Scott
 
Scott said:
Found it Patr II:

After I was positive that the code was right, it still didn't return
anything. No error, no warning, no data, no nothing....

So I played "chase the breakpoint" for a little while....

You know, it really helps to call ...TableAdapter.Fill() *BEFORE* you try
to iterate through the data in a dataset.

DOH!!!!!

Sorry about that,

No problem. Once you've struggled through finding the right pattern once,
it'll stick in your head for a long long time. In the end, much more
valuable than have a Wizard do it all for you!

-cd
 
No problem. Once you've struggled through finding the right pattern
once,
it'll stick in your head for a long long time. In the end, much more
valuable than have a Wizard do it all for you!

-cd

LOL

I'm 40 years old, formally trained in troubleshooting as an electronics
tech 20 years ago and have spent the last 20 years, more or less, fixing
any and everything that came my way. Electronic, plumbing, computers,
mechanical... it's all the same basic approach.

It's also true that you never remember how to do it if you only spent 2
minutes being told how by someone else but you never forget the serious
a** kicking you took for ten hours because Y was in between T and U rather
than between X and Z where it belongs.

And believe me, you get your a** handed to you many, many times in 20
years!

That's why I say that wisdom can be measured... just look at the thickness
of the callus on someone's forehead. (from beating thier head on the desk
or against a wall)

That's also why my blog is titled: "Pound head here".

Yea, I'll be taking my lumps over the next few months... but I think it'll
be well worth it to invest the effort into VC# and SAPI.

Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top