473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 30 '06 #1
10 1648
Scott wrote:
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}'",sCom mand)))
{
// 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
Jul 30 '06 #2
On Sun, 30 Jul 2006 17:51:17 -0400, Carl Daniel [VC++ MVP]
<cp*****************************@mvps.org.nospamwr ote:
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("C ommand='{0}'" ,
sCommands)))

{
// *** BROKEN*** Set string resp equal to the value of the
"Response" row at the correct index...
string resp =
sabineCommandsDataGridView.Select(String.Format("R esponse='{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
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 30 '06 #3
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Scott" wrote:
On Sun, 30 Jul 2006 17:51:17 -0400, Carl Daniel [VC++ MVP]
<cp*****************************@mvps.org.nospamwr ote:
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("C ommand='{0}'" ,
sCommands)))

{
// *** BROKEN*** Set string resp equal to the value of the
"Response" row at the correct index...
string resp =
sabineCommandsDataGridView.Select(String.Format("R esponse='{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
--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 30 '06 #4
On Sun, 30 Jul 2006 19:40:02 -0400, Peter Bromberg [C# MVP]
<pb*******@yahoo.nospammin.comwrote:
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

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 30 '06 #5
"Scott" <vo****@gawab.comwrote in message
news:op***************@ncd.dc.dc.cox.net...
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
Jul 31 '06 #6
On Sun, 30 Jul 2006 20:58:11 -0400, Carl Daniel [VC++ MVP]
<cp*****************************@mvps.org.nospamwr ote:

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" <vo****@gawab.comwrote in message
news:op***************@ncd.dc.dc.cox.net...
>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



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 31 '06 #7
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[i]["CompanyName"]);
}
}

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

Thanks for pointing me in the right direction!

Scott

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 31 '06 #8
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

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 31 '06 #9
"Scott" <vo****@gawab.comwrote in message
news:op***************@ncd.dc.dc.cox.net...
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
Jul 31 '06 #10
On Mon, 31 Jul 2006 12:25:09 -0400, Carl Daniel [VC++ MVP]
<cp*****************************@mvps.org.nospamwr ote:
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

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Aug 1 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kk | last post by:
Have 2 problems, any help is appreciated. Tab with Grids -------------- BL - fetching data from DB ( 5 secs - 10 rows) Grid Laod - 20 secs Grid Paint on tab change - 20 secs Problem: The...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
1
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and...
19
by: Simon Verona | last post by:
I'm not sure if I'm going down the correct route... I have a class which exposes a number of properties of an object (in this case the object represents a customer). Can I then use this...
1
by: Frustrated Developer via DotNetMonster.com | last post by:
I have developed a form that would allow the user to load and search a database several ways, by data range using two combo boxes, by specific number entered in a text box or all database entries....
19
by: Larry Lard | last post by:
In the old days (VB3 era), there was a thing called the Data Control, and you could use it to databind controls on forms to datasources, and so (as the marketing speak goes), 'create database...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
6
by: Wesley Peace | last post by:
I hate to cross post, but I've gotten no answer yet on a problem I'm having with visual studio 2008. I've created a series of forms with controls to access a Access database tables. The...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.