473,387 Members | 1,416 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.

Help with Access Database code

How come this code doesn't work...?

myConn.Open();
DataSet dtSet = new DataSet();
myCmd.Fill( dtSet, "security" );
DataTable dTable = dtSet.Tables[0];
string str;
str = (string)dtSet.Tables["security"].Row[0].["name"];
MessageBox.Show(str);

I get the message "Identifier expected".

In case you are wondering, I am trying to read the first row of a table
called "security" in an MS Access database. The column name is "name".
Nov 16 '05 #1
3 1223
Take the '.' out of the column reference;
str = (string)dtSet.Tables["security"].Row[0]["name"];
not:
str = (string)dtSet.Tables["security"].Row[0].["name"];

- Colin.

"Keith Smith" <ke*********@verizon.net> wrote in message
news:USgLd.1018$B64.695@trnddc07...
How come this code doesn't work...?

myConn.Open();
DataSet dtSet = new DataSet();
myCmd.Fill( dtSet, "security" );
DataTable dTable = dtSet.Tables[0];
string str;
str = (string)dtSet.Tables["security"].Row[0].["name"];
MessageBox.Show(str);

I get the message "Identifier expected".

In case you are wondering, I am trying to read the first row of a table
called "security" in an MS Access database. The column name is "name".

Nov 16 '05 #2
> Take the '.' out of the column reference;
str = (string)dtSet.Tables["security"].Row[0]["name"];
not:
str = (string)dtSet.Tables["security"].Row[0].["name"];

- Colin.


Thanks! That worked!

Is there a way to set the value of "str" to be the "next value in line" as
opposed to having to specify the particular row number? I know in the past
when I programmed in ASP I could create a dataset and then just scroll
through the dataset.
Nov 16 '05 #3
Try;
foreach(DataRow vRow in dtSet.Tables["security"].Rows)
str = (string)vRow["name"];

You even have a 'Select' method to process only those rows out of the
'security' table that meet a particular criteria.

You may want to look at strongly typed datasets, which allow you to move
away from late binding of table/field names. You can then refer to the
'name' field as Security.Name - saves hours of grief with finding a type
embedded in quotes, which will only show up at runtime (a typo on a stong
typed name will show up at compile time). Just MPOV.

- Colin

"Keith Smith" <ke*********@verizon.net> wrote in message
news:m_pLd.566$bF4.401@trnddc04...
Take the '.' out of the column reference;
str = (string)dtSet.Tables["security"].Row[0]["name"];
not:
str = (string)dtSet.Tables["security"].Row[0].["name"];

- Colin.
Thanks! That worked!

Is there a way to set the value of "str" to be the "next value in line" as
opposed to having to specify the particular row number? I know in the

past when I programmed in ASP I could create a dataset and then just scroll
through the dataset.

Nov 16 '05 #4

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

Similar topics

3
by: cooldv | last post by:
i am running a website on Windows 2000 server with ASP 3 webpages and Access 2000 database. (with a hosting company) traffic is slow at this time but expect to grow. lately i have been reading...
2
by: Bobby | last post by:
Hello everyone I have a question. The school I am working for is in the beginning process of having a webpage that will direct students to download there homework and be able to view there info...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
3
by: Mark Kolber | last post by:
I just migrated to Office 2003. When I opened an important Access database, Access 2003 promptly destroyed it. Unfortunately, there was a glitch in my backup routine and two folders, including...
2
by: Vladislav Moltchanov | last post by:
Recently I have changed from Acc97 to Acc2000 (I had to supply some data entry tools for field data collection for users still using Acc97). Among lot of other complications coming with Acc2000...
8
by: Steph | last post by:
Hi. I'm very new to MS Access and have been presented with an Access database of contacts by my employer. I am trying to redesign the main form of the database so that a button entitled...
1
by: Alpha | last post by:
I have a Window based application that shows up still running in the task manager when I close it. It reaches the "this.close" statement and then it stops at the "}" at the section of the...
16
by: peshekeedweller | last post by:
Using asp.net 1.1. vb.net 2003. I am trying to connect to a remote sql server 2000 on a virtual machine running windows 2000 server. I can connect through the server explorer in visual studio,...
6
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
9
by: O | last post by:
I need to do some lookups and updates on some legacy Access 2.0 files (they've from another vendor and I'm not in a position to update them). I was successful using VB6, but I've moved on to VS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.