What's wrong with my connection string to the Access db?

A

Aries

I have a connection string like this, anyone know how can I fix it?

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<body>
<!-- #include file = "linkx.inc" -->
<script language="C#" runat="server">


protected void Page_Load(Object sender, EventArgs e)
{
string mysql;
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\inetpub\\wwwroot\\break.mdb;";

mysql = "SELECT Date, Build, Count(*) as num FROM BVTbreak GROUP BY Date,
Build where status = 5 order by Build DESC;";
OleDbDataAdapter myCommand = OleDbDataAdapter(mysql, myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Waive");

MyDataGrid.DataSource=ds.Tables["Waive"].DefaultView;
MyDataGrid.DataBind();
}


I got the compilation error:

Line 18: OleDbAdapter myCommand = OleDbAdapter(mysql, myConnection);
 
C

Charles A. Lackman

Hello, I do not know much about C or C# but i do know VB. Here is how it
would be done in vb and you can modify it to work in the language you are
using.

Page Load Event

Dim AConnectionString as string = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\inetpub\wwwroot\break.mdb;"

**** There is a better place for the database*******

Dim ADataset as New Dataset

Dim ADataAdapter as new oledb.DataAdapter("SELECT Date, Build, Count(*) as
num FROM BVTbreak GROUP BY Date, Build where status = 5 order by Build
DESC;", AConnectionString)

ADataAdapter.Fill(ADataset, "Waive")

MyDataGrid.DataSource=ADataset.Tables("Waive").DefaultView

MyDataGrid.DataBind()

**** You don't need a connection object but it is better to use a command
object and parameters for your querries.

Chuck

Aries said:
I have a connection string like this, anyone know how can I fix it?

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<body>
<!-- #include file = "linkx.inc" -->
<script language="C#" runat="server">


protected void Page_Load(Object sender, EventArgs e)
{
string mysql;
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\inetpub\\wwwroot\\break.mdb;";

mysql = "SELECT Date, Build, Count(*) as num FROM BVTbreak GROUP BY Date,
Build where status = 5 order by Build DESC;";
OleDbDataAdapter myCommand = OleDbDataAdapter(mysql, myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Waive");

MyDataGrid.DataSource=ds.Tables["Waive"].DefaultView;
MyDataGrid.DataBind();
}


I got the compilation error:

Line 18: OleDbAdapter myCommand = OleDbAdapter(mysql, myConnection);




--

ÁÙ§Ú¥»¦ â
Bad.
 
K

Kevin Spencer

What exactly is "the compilation error?"

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Aries said:
I have a connection string like this, anyone know how can I fix it?

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<body>
<!-- #include file = "linkx.inc" -->
<script language="C#" runat="server">


protected void Page_Load(Object sender, EventArgs e)
{
string mysql;
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\inetpub\\wwwroot\\break.mdb;";

mysql = "SELECT Date, Build, Count(*) as num FROM BVTbreak GROUP BY Date,
Build where status = 5 order by Build DESC;";
OleDbDataAdapter myCommand = OleDbDataAdapter(mysql, myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Waive");

MyDataGrid.DataSource=ds.Tables["Waive"].DefaultView;
MyDataGrid.DataBind();
}


I got the compilation error:

Line 18: OleDbAdapter myCommand = OleDbAdapter(mysql, myConnection);




--

ÁÙ§Ú¥»¦â
Bad.
 
A

Aries

Sorry that I forgot to put down. Here is the error message

Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name
'OleDbDataAdapter' could not be found (are you missing a using directive or
an assembly reference?)

--

ÁÙ§Ú¥»¦â
Forever Bad.
Kevin Spencer said:
What exactly is "the compilation error?"

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Aries said:
I have a connection string like this, anyone know how can I fix it?

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<body>
<!-- #include file = "linkx.inc" -->
<script language="C#" runat="server">


protected void Page_Load(Object sender, EventArgs e)
{
string mysql;
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\inetpub\\wwwroot\\break.mdb;";

mysql = "SELECT Date, Build, Count(*) as num FROM BVTbreak GROUP BY Date,
Build where status = 5 order by Build DESC;";
OleDbDataAdapter myCommand = OleDbDataAdapter(mysql, myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Waive");

MyDataGrid.DataSource=ds.Tables["Waive"].DefaultView;
MyDataGrid.DataBind();
}


I got the compilation error:

Line 18: OleDbAdapter myCommand = OleDbAdapter(mysql, myConnection);




--

ÁÙ§Ú¥»¦â
Bad.
 
K

Kevin Spencer

Ah, thanks Aries! I should have spotted the problem before, but your reply
helped me to spot it this time. Your line of code reads:

OleDbDataAdapter myCommand = OleDbDataAdapter(mysql, myConnection);

It SHOULD read:

OleDbDataAdapter myCommand = new OleDbDataAdapter(mysql, myConnection);

You may not have known to use the new operator, as the C# documentation in
the .Net SDK lists the constructor method of a class as simply the class
name, while VB.Net's documentation specifically calls this function New.
However, every class constructor method must be called using the new
operator.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Aries said:
Sorry that I forgot to put down. Here is the error message

Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name
'OleDbDataAdapter' could not be found (are you missing a using directive or
an assembly reference?)

--

ÁÙ§Ú¥»¦â
Bad.
Kevin Spencer said:
What exactly is "the compilation error?"

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Aries" <a> wrote in message news:[email protected]...
I have a connection string like this, anyone know how can I fix it?

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<body>
<!-- #include file = "linkx.inc" -->
<script language="C#" runat="server">


protected void Page_Load(Object sender, EventArgs e)
{
string mysql;
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\inetpub\\wwwroot\\break.mdb;";

mysql = "SELECT Date, Build, Count(*) as num FROM BVTbreak GROUP BY Date,
Build where status = 5 order by Build DESC;";
OleDbDataAdapter myCommand = OleDbDataAdapter(mysql, myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Waive");

MyDataGrid.DataSource=ds.Tables["Waive"].DefaultView;
MyDataGrid.DataBind();
}


I got the compilation error:

Line 18: OleDbAdapter myCommand = OleDbAdapter(mysql, myConnection);
Forever
Bad.
 
A

Aries

It works. Thank you very much Kevin.

--

ÁÙ§Ú¥»¦â
Forever Bad.
Kevin Spencer said:
Ah, thanks Aries! I should have spotted the problem before, but your reply
helped me to spot it this time. Your line of code reads:

OleDbDataAdapter myCommand = OleDbDataAdapter(mysql, myConnection);

It SHOULD read:

OleDbDataAdapter myCommand = new OleDbDataAdapter(mysql, myConnection);

You may not have known to use the new operator, as the C# documentation in
the .Net SDK lists the constructor method of a class as simply the class
name, while VB.Net's documentation specifically calls this function New.
However, every class constructor method must be called using the new
operator.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Aries said:
Sorry that I forgot to put down. Here is the error message

Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: CS0246: The type or namespace name
'OleDbDataAdapter' could not be found (are you missing a using directive or
an assembly reference?)

--

ÁÙ§Ú¥»¦â
Bad.
Kevin Spencer said:
What exactly is "the compilation error?"

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Aries" <a> wrote in message I have a connection string like this, anyone know how can I fix it?

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<html>
<body>
<!-- #include file = "linkx.inc" -->
<script language="C#" runat="server">


protected void Page_Load(Object sender, EventArgs e)
{
string mysql;
OleDbConnection myConnection = new OleDbConnection();
myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\\inetpub\\wwwroot\\break.mdb;";

mysql = "SELECT Date, Build, Count(*) as num FROM BVTbreak GROUP BY Date,
Build where status = 5 order by Build DESC;";
OleDbDataAdapter myCommand = OleDbDataAdapter(mysql, myConnection);

DataSet ds = new DataSet();
myCommand.Fill(ds, "Waive");

MyDataGrid.DataSource=ds.Tables["Waive"].DefaultView;
MyDataGrid.DataBind();
}


I got the compilation error:

Line 18: OleDbAdapter myCommand = OleDbAdapter(mysql, myConnection);




--


ÁÙ§Ú¥»¦â
Forever
Bad.
 

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

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top