Newly getting started in C#

  • Thread starter Thread starter George
  • Start date Start date
G

George

hi all,

I am trying to make the jump from VB6 to C#. While I do have a couple of
books, the best way I can learn something is to write something I know. So
please forgive me in advance if this question sounds a bit off in the C#
terminology.

I am taking a simple thing like opening a MS Access database and filling a
listbox with names from 1 of the tables in the database.

I am using Visual Studio 2005 and I created a new project with 1 mdi form.

In VB I would create the connection to the database and connect to it in the
startup module (sub main). Then when needed in the program I would pass the
sql statement to a public subroutine to open the recordset, retrieve the
records and close the recordset.

While I believe I have the correct coding to connect to the database, open a
table, retrieve the needed field/column and then close the table for C#, I
cannot figure out where the best places are for the routines to go. Would I
put the connection routine in the program.cs module? I see that this has
been created in the program.cs module:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MDIMain());
}

so I was guessing that I could do a:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MDIMain());
ConnectToDatabase():
}

for my initial connection and have the routine ConnectToDatabase() in the
program.cs module.

The next question would be where do I put a "ExtractRecords" routine so that
all of the forms in the program could access the routine and extract from the
database? Would that go in the program.cs module as well?

Thank you for your support,

George
 
Hi,


--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.

In VB I would create the connection to the database and connect to it in
the
startup module (sub main). Then when needed in the program I would pass
the
sql statement to a public subroutine to open the recordset, retrieve the
records and close the recordset.

That is wrong, (both in VB6 and in .NET) you should only connect to the DB
when you need the data AND close it ASAP.
In .net you have a class DataSet that hold a number of tables, relationship,
etc kind of an in memory DB.
Take a look in MSDN to these classes DataSet , DataTable, DataView.
Also take a look (and see the examples) of how to use OleDbDataAdapter.
 
for my initial connection and have the routine ConnectToDatabase() in the
program.cs module.

As Ignacio said, your ConnectToDatabase() call should really go inside your
ExtractRecords() routine.
The next question would be where do I put a "ExtractRecords" routine so
that
all of the forms in the program could access the routine and extract from
the
database? Would that go in the program.cs module as well?

It may seem overkill, but it wouldn't hurt to go ahead and start a Data
Access Layer, even for just getting started. For starters, just create
another class file and start putting static routines in there. Then, from
your forms, call the static routines on that class.

When you start a new "real" project, you can just copy that class into your
new project. Or, if you intend to use the class across multiple projects,
put it into its own assembly.

namespace MyDAL
{
public class DataRoutines
{
public static DataSet ExtractRecords(object SomeCriteria)
{
// Open DB connection.
// Create and populate DataSet.
// Close & dispose DB connection.
return DataSetResult;
}
}
}


From your form:

DataSet mydata = MyDAL.DataRoutines.ExtractRecords("some criteria");
 
I took your advice and tried to figure this out. I create a new class file
as follows:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;

namespace Routines
{
public class DataRoutines
{
public static DataSet ExtractRecords(string strAccessConn)
{
// DataSet myDataSet = new DataSet();
OleDbConnection myAccessConn = null;
myAccessConn = new OleDbConnection(strAccessConn);

OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect,
myAccessConn);
OleDbDataAdapter myDataAdapter = new
OleDbDataAdapter(myAccessCommand);

myAccessConn.Open();
myDataAdapter.Fill(myDataSet, "series");

myAccessConn.Close();
DataTableCollection dta = myDataSet.Tables;
return myDataSet;
}
}
}


I immediately get an error when I try to run this:

The type or namespace name 'DataSet' could not be found (are you missing a
using directive or an assembly reference?)

Any ideas on what I did wrong?

Thanks,

George
 
George said:
I took your advice and tried to figure this out. I create a new class file
as follows:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;

namespace Routines
{
public class DataRoutines
{
public static DataSet ExtractRecords(string strAccessConn)
{
// DataSet myDataSet = new DataSet();
OleDbConnection myAccessConn = null;
myAccessConn = new OleDbConnection(strAccessConn);

OleDbCommand myAccessCommand = new
OleDbCommand(strAccessSelect,
myAccessConn);
OleDbDataAdapter myDataAdapter = new
OleDbDataAdapter(myAccessCommand);

myAccessConn.Open();
myDataAdapter.Fill(myDataSet, "series");

myAccessConn.Close();
DataTableCollection dta = myDataSet.Tables;
return myDataSet;
}
}
}


I immediately get an error when I try to run this:

The type or namespace name 'DataSet' could not be found (are you missing a
using directive or an assembly reference?)

Any ideas on what I did wrong?

Thanks,

George

The DataSet class is in the System.Data namespace, so add this at the top:

using System.Data;

Or, you can use the fully-qualified name everywhere like this:

System.Data.DataSet myDataSet = new System.Data.DataSet();

Adding the "using" statement at the top is probably easier.
 
[...]
I immediately get an error when I try to run this:

The type or namespace name 'DataSet' could not be found (are you missing
a
using directive or an assembly reference?)

Any ideas on what I did wrong?

From the MSDN documentation for the DataSet class: "Namespace: System.Data"
http://msdn2.microsoft.com/en-us/library/system.data.dataset(vs.80).aspx

The error specifically says "are you missing a using directive or assembly
reference?"

So, are you? Do you have a "using" directive that specifies "System.Data"?

While every now and then I run across a complier error that seems
relatively vague, I've found that the C# compiler most often provides very
useful, specific advice. If you simply read the error message, it often
describes very clearly what might be wrong and provides a strong
suggestion as to how you might fix it.

IMHO, that's the case here.

Pete
 
From the MSDN documentation for the DataSet class: "Namespace:
System.Data"
http://msdn2.microsoft.com/en-us/library/system.data.dataset(vs.80).aspx

The error specifically says "are you missing a using directive or
assembly reference?"

So, are you? Do you have a "using" directive that specifies
"System.Data"?
While every now and then I run across a complier error that seems
relatively vague, I've found that the C# compiler most often provides
very useful, specific advice. If you simply read the error message,
it often describes very clearly what might be wrong and provides a
strong suggestion as to how you might fix it.

IMHO, that's the case here.

Welcome to "George". He's been posting on the C++ groups for a while now,
with some sort of automated system creating multiposts all over the place.

There's been some speculation that he's an automated agent, although I don't
agree.
 
Welcome to "George".  He's been posting on the C++ groups for a while now,
with some sort of automated system creating multiposts all over the place.

There's been some speculation that he's an automated agent, although I don't
agree.

That wasnt really nice Ben, nice Ben, nice Ben, nice Ben

error 8000231321

;)

I'd use ADO for db access... those toys coming with c# IMHO is a bit
numbing (numming?) on the creative mind...
//CY
 
- Visa citerad text -

Dont be offended, was trying to make a joke, still adding something to
the OP:s question

being a mvp you might help?

not native to english so it might come over a tad wrong... no pun
intended, just writing what fell into my head.

Will look at the link, but if we start looking for spammers with that
scope then ill be banned too, cant separate a public from a static and
where to use one or the other ;)

//CY
 
Looked at the link, here is an Idea: go hunt why recently 4-5
(internet) cables got damaged to egypt/iran/iraq instead... echelon
installations? or why some spooks writing maleware for my personal
puter? he seems harmless. He seems to respond and might be using you
as a ballplank or a thinktank - well you decide if you want to answer.

or is it an AI, will he take the turing test?

//CY
 
First a little note: top posting *and* using a -- signature
marker mess up peoples reply.
That is wrong, (both in VB6 and in .NET) you should only connect to the DB
when you need the data AND close it ASAP.

Does ADO have a connection pool ??

Arne
 
hi all,

I am trying to make the jump from VB6 to C#. While I do have a couple
of
books, the best way I can learn something is to write something I
know. So
please forgive me in advance if this question sounds a bit off in the
C#
terminology.


I am taking a simple thing like opening a MS Access database and
filling a
listbox with names from 1 of the tables in the database.


I am using Visual Studio 2005 and I created a new project with 1 mdi
form.


In VB I would create the connection to the database and connect to it
in the
startup module (sub main). Then when needed in the program I would
pass the
sql statement to a public subroutine to open the recordset, retrieve
the
records and close the recordset.


While I believe I have the correct coding to connect to the database,
open a
table, retrieve the needed field/column and then close the table for
C#, I
cannot figure out where the best places are for the routines to go.
Would I
put the connection routine in the program.cs module? I see that this
has
been created in the program.cs module:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MDIMain());
}


so I was guessing that I could do a:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MDIMain());
ConnectToDatabase():
}


for my initial connection and have the routine ConnectToDatabase() in
the
program.cs module.


The next question would be where do I put a "ExtractRecords" routine
so that
all of the forms in the program could access the routine and extract
from the
database? Would that go in the program.cs module as well?


Thank you for your support,


George



Ignacio Machin ( .NET/ C# MVP ) Visa profil
Fler alternativ 11 Feb, 17:52

Nyhetsgrupper: microsoft.public.dotnet.languages.csharp
Från: "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.com>
Hi,

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.


In VB I would create the connection to the database and connect to it in
the
startup module (sub main). Then when needed in the program I would pass
the
sql statement to a public subroutine to open the recordset, retrieve the
records and close the recordset.


That is wrong, (both in VB6 and in .NET) you should only connect to
the DB
when you need the data AND close it ASAP.
In .net you have a class DataSet that hold a number of tables,
relationship,
etc kind of an in memory DB.
Take a look in MSDN to these classes DataSet , DataTable, DataView.
Also take a look (and see the examples) of how to use
OleDbDataAdapter.


- Dölj citerad text -
- Visa citerad text -
While I believe I have the correct coding to connect to the database, open
a
table, retrieve the needed field/column and then close the table for C#, I
cannot figure out where the best places are for the routines to go. Would
I
put the connection routine in the program.cs module? I see that this has
been created in the program.cs module:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MDIMain());
}
so I was guessing that I could do a:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MDIMain());
ConnectToDatabase():
}

for my initial connection and have the routine ConnectToDatabase() in the
program.cs module.

The next question would be where do I put a "ExtractRecords" routine so
that
all of the forms in the program could access the routine and extract from
the
database? Would that go in the program.cs module as well?

Thank you for your support,

George

Scott Roberts Visa profil
Fler alternativ 11 Feb, 18:17

for my initial connection and have the routine ConnectToDatabase() in the
program.cs module.


As Ignacio said, your ConnectToDatabase() call should really go inside
your
ExtractRecords() routine.

The next question would be where do I put a "ExtractRecords" routine so
that
all of the forms in the program could access the routine and extract from
the
database? Would that go in the program.cs module as well?


It may seem overkill, but it wouldn't hurt to go ahead and start a
Data
Access Layer, even for just getting started. For starters, just
create
another class file and start putting static routines in there. Then,
from
your forms, call the static routines on that class.

When you start a new "real" project, you can just copy that class into
your
new project. Or, if you intend to use the class across multiple
projects,
put it into its own assembly.


namespace MyDAL
{
public class DataRoutines
{
public static DataSet ExtractRecords(object SomeCriteria)
{
// Open DB connection.
// Create and populate DataSet.
// Close & dispose DB connection.
return DataSetResult;
}
}



}


From your form:

DataSet mydata = MyDAL.DataRoutines.ExtractRecords("some criteria");
I took your advice and tried to figure this out. I create a new class
file
as follows:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;


namespace Routines
{
public class DataRoutines
{
public static DataSet ExtractRecords(string strAccessConn)
{
// DataSet myDataSet = new DataSet();
OleDbConnection myAccessConn = null;
myAccessConn = new OleDbConnection(strAccessConn);


OleDbCommand myAccessCommand = new
OleDbCommand(strAccessSelect,
myAccessConn);
OleDbDataAdapter myDataAdapter = new
OleDbDataAdapter(myAccessCommand);


myAccessConn.Open();
myDataAdapter.Fill(myDataSet, "series");


myAccessConn.Close();
DataTableCollection dta = myDataSet.Tables;
return myDataSet;
}
}



}


I immediately get an error when I try to run this:

The type or namespace name 'DataSet' could not be found (are you
missing a
using directive or an assembly reference?)


Any ideas on what I did wrong?


Thanks,


George


[...]
I immediately get an error when I try to run this:
The type or namespace name 'DataSet' could not be found (are you missing
a
using directive or an assembly reference?)

Any ideas on what I did wrong?



From the MSDN documentation for the DataSet class: "Namespace:
System.Data"
http://msdn2.microsoft.com/en-us/library/system.data.dataset(vs.80).aspx

The error specifically says "are you missing a using directive or
assembly
reference?"


So, are you? Do you have a "using" directive that specifies
"System.Data"?


While every now and then I run across a complier error that seems
relatively vague, I've found that the C# compiler most often provides
very
useful, specific advice. If you simply read the error message, it
often
describes very clearly what might be wrong and provides a strong
suggestion as to how you might fix it.


IMHO, that's the case here.


Pete






I took your advice and tried to figure this out. I create a new class file
as follows:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;

namespace Routines
{
public class DataRoutines
{
public static DataSet ExtractRecords(string strAccessConn)
{
// DataSet myDataSet = new DataSet();
OleDbConnection myAccessConn = null;
myAccessConn = new OleDbConnection(strAccessConn);

OleDbCommand myAccessCommand = new
OleDbCommand(strAccessSelect,
myAccessConn);
OleDbDataAdapter myDataAdapter = new
OleDbDataAdapter(myAccessCommand);

myAccessConn.Open();
myDataAdapter.Fill(myDataSet, "series");

myAccessConn.Close();
DataTableCollection dta = myDataSet.Tables;
return myDataSet;
}
}
}

I immediately get an error when I try to run this:

The type or namespace name 'DataSet' could not be found (are you missing a
using directive or an assembly reference?)

Any ideas on what I did wrong?



George



The DataSet class is in the System.Data namespace, so add this at the
top:

using System.Data;


Or, you can use the fully-qualified name everywhere like this:


System.Data.DataSet myDataSet = new System.Data.DataSet();


Adding the "using" statement at the top is probably easier.
From the MSDN documentation for the DataSet class: "Namespace:
System.Data"
http://msdn2.microsoft.com/en-us/library/system.data.dataset(vs.80).aspx
The error specifically says "are you missing a using directive or
assembly reference?"

So, are you? Do you have a "using" directive that specifies
"System.Data"?
While every now and then I run across a complier error that seems
relatively vague, I've found that the C# compiler most often provides
very useful, specific advice. If you simply read the error message,
it often describes very clearly what might be wrong and provides a
strong suggestion as to how you might fix it.

IMHO, that's the case here.



Welcome to "George". He's been posting on the C++ groups for a while
now,
with some sort of automated system creating multiposts all over the
place.

There's been some speculation that he's an automated agent, although I
don't
agree.
Welcome to "George". He's been posting on the C++ groups for a while now,
with some sort of automated system creating multiposts all over the place.
There's been some speculation that he's an automated agent, although I don't
agree.



That wasnt really nice Ben, nice Ben, nice Ben, nice Ben

error 8000231321


;)


I'd use ADO for db access... those toys coming with c# IMHO is a bit
numbing (numming?) on the creative mind...
//CY


That wasnt really nice Ben, nice Ben, nice Ben, nice Ben



Hey, not cool! I intentionally didn't comment (ok, deleted before
posting)
on George's programming ability. What I wrote are purely facts, as
you can
verify by looking at:

http://groups.google.com/group/microsoft.public.win32.programmer.kern...

error 8000231321



I'd use ADO for db access... those toys coming with c# IMHO is a bit
numbing (numming?) on the creative mind...
//CY
- Visa citerad text -



Dont be offended, was trying to make a joke, still adding something
to
the OP:s question

being a mvp you might help?


not native to english so it might come over a tad wrong... no pun
intended, just writing what fell into my head.


Will look at the link, but if we start looking for spammers with that
scope then ill be banned too, cant separate a public from a static
and
where to use one or the other ;)


//CY

Looked at the link, here is an Idea: go hunt why recently 4-5
(internet) cables got damaged to egypt/iran/iraq instead... echelon
installations? or why some spooks writing maleware for my personal
puter? he seems harmless. He seems to respond and might be using you
as a ballplank or a thinktank - well you decide if you want to
answer.

or is it an AI, will he take the turing test?


//CY

First a little note: top posting *and* using a -- signature
marker mess up peoples reply.

That is wrong, (both in VB6 and in .NET) you should only connect to the DB
when you need the data AND close it ASAP.


Does ADO have a connection pool ??


Arne





Ignacio Machin ( .NET/ C# MVP ) wrote:
 >

First a little note: top posting *and* using a -- signature
marker mess up peoples reply.

 >That is wrong, (both in VB6 and in .NET) you should only connect to
the DB
 >when you need the data AND close it ASAP.

Does ADO have a connection pool ??

Arne

Connection pools in ado.net as to micro:
http://msdn2.microsoft.com/en-us/library/8xx3tyca(VS.85).aspx
but I guess if u close it u loose it...


using (SqlConnection connection = new SqlConnection(
"Integrated Security=SSPI;Initial Catalog=Northwind"))
{
connection.Open();
// Pool A is created.
}

using (SqlConnection connection = new SqlConnection(
"Integrated Security=SSPI;Initial Catalog=pubs"))
{
connection.Open();
// Pool B is created because the connection strings differ.
}

using (SqlConnection connection = new SqlConnection(
"Integrated Security=SSPI;Initial Catalog=Northwind"))
{
connection.Open();
// The connection string matches pool A.
}

!top posting? that means I must reply with all left of prev mess to
comply? Ill think about that... did it your way, did it get better?
 
A couple things:

Scott - thank you for clearing that up for me.

Peter - sorry to bore you, but I am new to this.

Ben - I am not sure what you are talking about. I have not been posting on
any C boards other than this one and this is my second topic that I has
posted. Before you go accusing someone of something you probably should take
the time to find out what you are talking about.
 
I take back some of what I said to Peter...but not all.

I just went through the link above and kept going through the other links
until I saw what you guys are talking about. In the google groups there is
an account that has been posting on boards since 2003. The email/name of the
account is
(e-mail address removed). I wouldnt care, but this topic is showing
as the latest posting for that user. If you look at my
account/profile/history there is an obvious difference between me and whoever
that other account belongs to.

My question/concern is why is this topic being put in to that person? I
tried to look for a way to question google I could not find one. I have no
idea why this latest posting is being pushed on to someone elses profile.
 
hi all,

I am trying to make the jump from VB6 to C#.  While I do have a couple
of
books, the best way I can learn something is to write something I
know.  So
please forgive me in advance if this question sounds a bit off in the
C#
terminology.

I am taking a simple thing like opening a MS Access database and
filling a
listbox with names from 1 of the tables in the database.

I am using Visual Studio 2005 and I created a new project with 1 mdi
form.

In VB I would create the connection to the database and connect to it
in the
startup module (sub main).  Then when needed in the program I would
pass the
sql statement to a public subroutine to open the recordset, retrieve
the
records and close the recordset.

While I believe I have the correct coding to connect to the database,
open a
table, retrieve the needed field/column and then close the table for
C#, I
cannot figure out where the best places are for the routines to go.
Would I
put the connection routine in the program.cs module?  I see that this
has
been created in the program.cs module:
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MDIMain());
        }

so I was guessing that I could do a:
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MDIMain());
            ConnectToDatabase():
        }

for my initial connection and have the routine ConnectToDatabase() in
the
program.cs module.

The next question would be where do I put a "ExtractRecords" routine
so that
all of the forms in the program could access the routine and extract
from the
database?  Would that go in the program.cs module as well?

Thank you for your support,

George

Ignacio Machin ( .NET/ C# MVP )    Visa profil
  Fler alternativ 11 Feb, 17:52

Nyhetsgrupper: microsoft.public.dotnet.languages.csharp
Från: "Ignacio Machin \( .NET/ C# MVP \)" <machin TA
laceupsolutions.com>
Hi,

--
Ignacio Machinhttp://www.laceupsolutions.com
Mobile & warehouse Solutions.
In VB I would create the connection to the database and connect to it in
the
startup module (sub main).  Then when needed in the program I would pass
the
sql statement to a public subroutine to open the recordset, retrieve the
records and close the recordset.

That is wrong, (both in VB6 and in .NET) you should only connect to
the DB
when you need the data AND close it ASAP.
In .net you have a class DataSet that hold a number of tables,
relationship,
etc kind of an in memory DB.
Take a look in MSDN to these classes DataSet , DataTable, DataView.
Also take a look (and see the examples) of how to use
OleDbDataAdapter.

- Dölj citerad text -
- Visa citerad text -
While I believe I have the correct coding to connect to the database, open
a
table, retrieve the needed field/column and then close the table for C#,I
cannot figure out where the best places are for the routines to go.  Would
I
put the connection routine in the program.cs module?  I see that this has
been created in the program.cs module:
       static void Main()
       {
           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(false);
           Application.Run(new MDIMain());
       }
so I was guessing that I could do a:
       static void Main()
       {
           Application.EnableVisualStyles();
           Application.SetCompatibleTextRenderingDefault(false);
           Application.Run(new MDIMain());
           ConnectToDatabase():
       }
for my initial connection and have the routine ConnectToDatabase() in the
program.cs module.
The next question would be where do I put a "ExtractRecords" routine so
that
all of the forms in the program could access the routine and extract from
the
database?  Would that go in the program.cs module as well?
Thank you for your support,
George

Scott Roberts    Visa profil
  Fler alternativ 11 Feb, 18:17
for my initial connection and have the routine ConnectToDatabase() in the
program.cs module.

As Ignacio said, your ConnectToDatabase() call should really go inside
your
ExtractRecords() routine.
The next question would be where do I put a "ExtractRecords" routine so
that
all of the forms in the program could access the routine and extract from
the
database?  Would that go in the program.cs module as well?

It may seem overkill, but it wouldn't hurt to go ahead and start a
Data
Access Layer, even for just getting started. For starters, just
create
another class file and start putting static routines in there. Then,
from
your forms, call the static routines on that class.

When you start a new "real" project, you can just copy that class into
your
new project. Or, if you intend to use the class across multiple
projects,
put it into its own assembly.

namespace MyDAL
{
  public class DataRoutines
  {
    public static DataSet ExtractRecords(object SomeCriteria)
    {
      // Open DB connection.
      // Create and populate DataSet.
      // Close & dispose DB connection.
      return DataSetResult;
    }
  }

}

From your form:

DataSet mydata = MyDAL.DataRoutines.ExtractRecords("some criteria");
I took your advice and tried to figure this out.  I create a new class
file
as follows:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;

namespace Routines
{
    public class DataRoutines
    {
        public static DataSet ExtractRecords(string strAccessConn)
        {
 //           DataSet myDataSet = new DataSet();
            OleDbConnection myAccessConn = null;
            myAccessConn = new OleDbConnection(strAccessConn);

            OleDbCommand myAccessCommand = new
OleDbCommand(strAccessSelect,
myAccessConn);
            OleDbDataAdapter myDataAdapter = new
OleDbDataAdapter(myAccessCommand);

            myAccessConn.Open();
            myDataAdapter.Fill(myDataSet, "series");

            myAccessConn.Close();
            DataTableCollection dta = myDataSet.Tables;
            return myDataSet;
        }
    }

}

I immediately get an error when I try to run this:

The type or namespace name 'DataSet' could not be found (are you
missing a
using directive or an assembly reference?)

Any ideas on what I did wrong?

Thanks,

George

[...]
I immediately get an error when I try to run this:
The type or namespace name 'DataSet' could not be found (are you missing
a
using directive or an assembly reference?)
Any ideas on what I did wrong?

 From the MSDN documentation for the DataSet class: "Namespace:
System.Data"http://msdn2.microsoft.com/en-us/library/system.data.dataset(vs.80).aspx

The error specifically says "are you missing a using directive or
assembly
reference?"

So, are you?  Do you have a "using" directive that specifies
"System.Data"?

While every now and then I run across a complier error that seems
relatively vague, I've found that the C# compiler most often provides
very
useful, specific advice.  If you simply read the error message, it
often
describes very clearly what might be wrong and provides a strong
suggestion as to how you might fix it.

IMHO, that's the case here.

Pete


I took your advice and tried to figure this out.  I create a new class file
as follows:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
namespace Routines
{
   public class DataRoutines
   {
       public static DataSet ExtractRecords(string strAccessConn)
       {
//           DataSet myDataSet = new DataSet();
           OleDbConnection myAccessConn = null;
           myAccessConn = new OleDbConnection(strAccessConn);
           OleDbCommand myAccessCommand = new
OleDbCommand(strAccessSelect,
myAccessConn);
           OleDbDataAdapter myDataAdapter = new
OleDbDataAdapter(myAccessCommand);
           myAccessConn.Open();
           myDataAdapter.Fill(myDataSet, "series");
           myAccessConn.Close();
           DataTableCollection dta = myDataSet.Tables;
           return myDataSet;
       }
   }
}
I immediately get an error when I try to run this:
The type or namespace name 'DataSet' could not be found (are you missinga
using directive or an assembly reference?)
Any ideas on what I did wrong?
Thanks,
George

The DataSet class is in the System.Data namespace, so add this at the
top:

using System.Data;

Or, you can use the fully-qualified name everywhere like this:

System.Data.DataSet myDataSet = new System.Data.DataSet();

Adding the "using" statement at the top is probably easier.
From the MSDN documentation for the DataSet class: "Namespace:
System.Data"
http://msdn2.microsoft.com/en-us/library/system.data.dataset(vs.80).aspx
The error specifically says "are you missing a using directive or
assembly reference?"
So, are you?  Do you have a "using" directive that specifies
"System.Data"?
While every now and then I run across a complier error that seems
relatively vague, I've found that the C# compiler most often provides
very useful, specific advice.  If you simply read the error message,
it often describes very clearly what might be wrong and provides a
strong suggestion as to how you might fix it.
IMHO, that's the case here.

Welcome to "George".  He's been posting on the C++ groups for a while
now,
with some sort of automated system creating multiposts all over the
place.

There's been some speculation that he's an automated agent, although I
don't
agree.
Pete
Welcome to "George".  He's been posting on the C++ groups for a while now,
with some sort of automated system creating multiposts all over the place.
There's been some speculation that he's an automated agent, although I don't
agree.

That wasnt really nice Ben, nice Ben, nice Ben, nice Ben

error 8000231321

;)

I'd use ADO for db access... those toys coming with c# IMHO is a bit
numbing (numming?) on the creative mind...
//CY

That wasnt really nice Ben, nice Ben, nice Ben, nice Ben

Hey, not cool!  I intentionally didn't comment (ok, deleted before
posting)
on George's programming ability.  What I wrote are purely facts, as
you can
verify by looking at:

http://groups.google.com/group/microsoft.public.win32.programmer.kern...
error 8000231321
;)
I'd use ADO for db access... those toys coming with c# IMHO is a bit
numbing (numming?) on the creative mind...
//CY
- Visa citerad text -

Dont be offended, was trying to make a joke, still adding something
to
the OP:s question

being a mvp you might help?

not native to english so it might come over a tad wrong... no pun
intended, just writing what fell into my head.

Will look at the link, but if we start looking for spammers with that
scope then ill be banned too, cant separate a public from a static
and
where to use one or the other ;)

//CY

Looked at the link, here is an Idea: go hunt why recently 4-5
(internet) cables got damaged to egypt/iran/iraq instead... echelon
installations? or why some spooks writing maleware for my personal
puter? he seems harmless. He seems to respond and might be using you
as a ballplank or a thinktank - well you decide if you want to
answer.

or is it an AI, will he take the turing test?

//CY
Ignacio Machin ( .NET/ C# MVP ) wrote:
 >

First a little note: top posting *and* using a -- signature
marker mess up peoples reply.

 >That is wrong, (both in VB6 and in .NET) you should only connect to
the DB
 >when you need the data AND close it ASAP.

Does ADO have a connection pool ??

Arne

Ignacio Machin ( .NET/ C# MVP ) wrote:
 >
First a little note: top posting *and* using a -- signature
marker mess up peoples reply.
 >That is wrong, (both in VB6 and in .NET) you should only connect to
the DB
 >when you need the data AND close it ASAP.
Does ADO have a connection pool ??

Connection pools in ado.net as to micro:http://msdn2.microsoft.com/en-us/library/8xx3tyca(VS.85).aspx
but I guess if u close it u loose it...

using (SqlConnection connection = new SqlConnection(
  "Integrated Security=SSPI;Initial Catalog=Northwind"))
    {
        connection.Open();
        // Pool A is created.
    }

using (SqlConnection connection = new SqlConnection(
  "Integrated Security=SSPI;Initial Catalog=pubs"))
    {
        connection.Open();
        // Pool B is created because the connection strings differ..
    }

using (SqlConnection connection = new SqlConnection(
  "Integrated Security=SSPI;Initial Catalog=Northwind"))
    {
        connection.Open();
        // The connection string matches pool A.
    }

!top posting? that means I must reply with all left of prev mess to
comply? Ill think about that... did it your way, did it get better?

Not responding, AI?

//CY
 
On Feb 12, 2:34 pm, (e-mail address removed) wrote:

<snip>

"Not top posting" isn't the same as "not snipping". Whether you're top
posting or not, there's never a need to include all of a previous post
unless every bit of it is relevant to what you're saying.

Jon
 
George said:
I take back some of what I said to Peter...but not all.

I just went through the link above and kept going through the other
links until I saw what you guys are talking about. In the google
groups there is an account that has been posting on boards since
2003. The email/name of the account is
(e-mail address removed). I wouldnt care, but this topic is
showing as the latest posting for that user. If you look at my
account/profile/history there is an obvious difference between me and
whoever that other account belongs to.

Because the both of you are posting using the same sender address.
My question/concern is why is this topic being put in to that person?
I tried to look for a way to question google I could not find one. I
have no idea why this latest posting is being pushed on to someone
elses profile.

If you are indeed a different person than the George posting on vc.language
then I'm sorry for (1) confusing you too and (2) attributing his faults to
you and (3) doing so in public, and would like to apologize for that.
 
I take back some of what I said to Peter...but not all.

Of what you wrote: "sorry to bore you, but I am new to this". So, the
part you don't take back is "sorry to bore you"? Or is it "I am new to
this"?

I don't really understand your reply at all. I haven't commented on the
identification under which you posted at all, and yet that appears to be
all you're writing about here. All I ever wrote to you was intended to a)
answer your immediate question, and b) help you understand better how you
could have answered the question yourself.

Pete
 
On Feb 12, 2:34 pm, (e-mail address removed) wrote:

<snip>

"Not top posting" isn't the same as "not snipping". Whether you're top
posting or not, there's never a need to include all of a previous post
unless every bit of it is relevant to what you're saying.

Jon

I thought that was what im doing.. but will stop, less for me to think
about...
just thought that was what I was doing... they will be long...

//CY
 
Back
Top