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

Out of Scope

The line below with nametest in it give out of scope when run. Why? There is
data in the table.

using System;
using System.Data;
using System.Data.OleDb;

namespace DataFM_Access_Data
{

class AccessConv
{

[STAThread]
static void Main()
{
string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=mmrs.mdb";
string strAccessSelect = "Select * from Customers";
DataSet myDataSet = new DataSet();
myDataSet.Tables.Add("Customers");
OleDbConnection myAccessConn = new OleDbConnection(strAccessConn);
myAccessConn.Open();
OleDbCommand myAccessDataSetCmd = new
OleDbCommand(strAccessSelect,myAccessConn);
OleDbDataReader dtrAccess = myAccessDataSetCmd.ExecuteReader();
if (dtrAccess.Read())
{
string nameTest= dtrAccess["CompanyName"].ToString();
^gives out of scope?
}
myAccessConn.Close();
}

}
}
}
Nov 17 '05 #1
2 1291
Maybe it would be better to write
int custIdCol = dtrAccess.GetOrdinal("CompanyName");

while (dtrAccess.Read())
{
string nameTest= dtrAccess.GetString(custIdCol );
}
--
Vadym Stetsyak aka Vadmyst

"Dave" <Da**@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
The line below with nametest in it give out of scope when run. Why? There is data in the table.

using System;
using System.Data;
using System.Data.OleDb;

namespace DataFM_Access_Data
{

class AccessConv
{

[STAThread]
static void Main()
{
string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=mmrs.mdb";
string strAccessSelect = "Select * from Customers";
DataSet myDataSet = new DataSet();
myDataSet.Tables.Add("Customers");
OleDbConnection myAccessConn = new OleDbConnection(strAccessConn);
myAccessConn.Open();
OleDbCommand myAccessDataSetCmd = new
OleDbCommand(strAccessSelect,myAccessConn);
OleDbDataReader dtrAccess = myAccessDataSetCmd.ExecuteReader();
if (dtrAccess.Read())
{
string nameTest= dtrAccess["CompanyName"].ToString();
^gives out of scope?
}
myAccessConn.Close();
}

}
}
}

Nov 17 '05 #2
Dave,

Nothing seeems to be out of scope there. Maybe you try to access the
nameTest variable after closing the block:
if (dtrAccess.Read())
{
string nameTest= dtrAccess["CompanyName"].ToString();
}
Console.WriteLine(nameTest); // this would be 'out of scope'
Regards - Octavio

"Dave" <Da**@discussions.microsoft.com> escribió en el mensaje
news:60**********************************@microsof t.com... The line below with nametest in it give out of scope when run. Why? There
is
data in the table.

using System;
using System.Data;
using System.Data.OleDb;

namespace DataFM_Access_Data
{

class AccessConv
{

[STAThread]
static void Main()
{
string strAccessConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=mmrs.mdb";
string strAccessSelect = "Select * from Customers";
DataSet myDataSet = new DataSet();
myDataSet.Tables.Add("Customers");
OleDbConnection myAccessConn = new OleDbConnection(strAccessConn);
myAccessConn.Open();
OleDbCommand myAccessDataSetCmd = new
OleDbCommand(strAccessSelect,myAccessConn);
OleDbDataReader dtrAccess = myAccessDataSetCmd.ExecuteReader();
if (dtrAccess.Read())
{
string nameTest= dtrAccess["CompanyName"].ToString();
^gives out of scope?
}
myAccessConn.Close();
}

}
}
}

Nov 17 '05 #3

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

Similar topics

6
by: pembed2003 | last post by:
Hi all, I am reading the book "C++ How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
5
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
8
by: TTroy | last post by:
I have a few questions about "scope" and "visibility," which seem like two different things. To me "visibility" of the name of a function or object is the actual code that can use it in an...
7
by: Christian Christmann | last post by:
Hi, I've a a question on the specifier extern. Code example: void func( void ) { extern int e; //...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
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: 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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.