By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,542 Members | 1,740 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,542 IT Pros & Developers. It's quick & easy.

MySQL & Datagrid using C# - getting compile error

P: n/a
Trying to connect to MySQL db on localhost, and populate datagrid from a
dataset using code inline method.

Getting the following compile error:

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

I downloaded the add on for connecting to MySQL using ADO.NET and installed
it, but am still getting this error. Anybody ever run into this before?
My Code:
<%@ Page Language="C#" %>
<%@ import namespace="CoreLab.MySql" %>

<script runat="server">

private void Page_Load(object sender, System.EventArgs e)
{

// create a connection
MySqlConnection oMySqlConn = new MySqlConnection();
oMySqlConn.ConnectionString = "User ID=myuserid;" +
"Password=mypassword;" +
"Host=localhost;" +
"Port=3306;" +
"Database=mydatabase;" +
"Direct=true;" +
"Protocol=TCP;" +
"Compress=false;" +
"Pooling=true;" +
"Min Pool Size=0;" +
"Max Pool Size=100;" +
"Connection Lifetime=0";
//open connection
oMySqlConn.Open();

// create a data adapter
string querystring = "select * from <database>.<table name> where
date='2004-06-01'"
OleDbDataAdapter da = new OleDbDataAdapter(querystring,
myConnection);

// create a new dataset
DataSet ds = new DataSet();

// fill dataset
da.Fill(ds, "GuidingErr");

// Attach DataSet to DataGrid
DataGrid1.DataSource = ds;
DataGrid1.DataBind();

oMySqlConn.Close();
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server"></asp:DataGrid>
</form>
</body>
</html>
Nov 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hello,

Try to add this row at the beginning of your code:

<%@ Register TagPrefix="cr" Namespace="CoreLab.MySql"
Assembly="CoreLab.MySql, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=09af7300eec23701" %>
Nov 18 '05 #2

P: n/a
I had to make some other changes to my code to get this to work, so I'm
posting my new code in case anybody else needs this info in the future and
comes across this thread.

Thanks again for your help Vladimir!

My Code:

<%@ Page Language="C#" Debug="true" %>
<%@ Register TagPrefix="cr" Namespace="CoreLab.MySql"
Assembly="CoreLab.MySql, Version=2.40.1.0, Culture=neutral,
PublicKeyToken=09af7300eec23701" %>
<%@ import Namespace="CoreLab.MySql" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">

private void Page_Load(object sender, System.EventArgs e)
{

// create a connection
MySqlConnection oMySqlConn = new MySqlConnection();
oMySqlConn.ConnectionString = "User ID=<user id>;" +
"Password=<password>;" +
"Host=localhost;" +
"Database=<db name>;" +
"Direct=true;" +
"Protocol=TCP;" +
"Compress=false;";
string querystring = "select fields from table";

MySqlCommand mySqlCommand = new
CoreLab.MySql.MySqlCommand(querystring);

MySqlDataAdapter da = new CoreLab.MySql.MySqlDataAdapter();

DataSet ds = new DataSet();

mySqlCommand.Connection = oMySqlConn;

da.SelectCommand = mySqlCommand;

oMySqlConn.Open();
// fill dataset
da.Fill(ds, "Results");

// Attach DataSet to DataGrid
DataGrid1.DataSource = ds;
DataGrid1.DataBind();

oMySqlConn.Close();
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server">
<HeaderStyle font-bold="True" forecolor="White"
backcolor="Gray"></HeaderStyle>
<AlternatingItemStyle
backcolor="LightGray"></AlternatingItemStyle>
</asp:DataGrid>
</form>
</body>
</html>

"Vladimir Zheleznyak" <ik**@crlab.com> wrote in message
news:34**************************@posting.google.c om...
Hello,

Try to add this row at the beginning of your code:

<%@ Register TagPrefix="cr" Namespace="CoreLab.MySql"
Assembly="CoreLab.MySql, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=09af7300eec23701" %>

Nov 18 '05 #3

P: n/a
Note that the version value in my Register directive differs from Vladimir's
example. Be sure that you check your version information and put the right
value in there or the compiler won't like it.

-Erik
"Erik H." <er*********@wwireless.com> wrote in message
news:#D**************@TK2MSFTNGP11.phx.gbl...
I had to make some other changes to my code to get this to work, so I'm
posting my new code in case anybody else needs this info in the future and
comes across this thread.

Thanks again for your help Vladimir!

My Code:

<%@ Page Language="C#" Debug="true" %>
<%@ Register TagPrefix="cr" Namespace="CoreLab.MySql"
Assembly="CoreLab.MySql, Version=2.40.1.0, Culture=neutral,
PublicKeyToken=09af7300eec23701" %>
<%@ import Namespace="CoreLab.MySql" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">

private void Page_Load(object sender, System.EventArgs e)
{

// create a connection
MySqlConnection oMySqlConn = new MySqlConnection();
oMySqlConn.ConnectionString = "User ID=<user id>;" +
"Password=<password>;" +
"Host=localhost;" +
"Database=<db name>;" +
"Direct=true;" +
"Protocol=TCP;" +
"Compress=false;";
string querystring = "select fields from table";

MySqlCommand mySqlCommand = new
CoreLab.MySql.MySqlCommand(querystring);

MySqlDataAdapter da = new CoreLab.MySql.MySqlDataAdapter();

DataSet ds = new DataSet();

mySqlCommand.Connection = oMySqlConn;

da.SelectCommand = mySqlCommand;

oMySqlConn.Open();
// fill dataset
da.Fill(ds, "Results");

// Attach DataSet to DataGrid
DataGrid1.DataSource = ds;
DataGrid1.DataBind();

oMySqlConn.Close();
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server">
<HeaderStyle font-bold="True" forecolor="White"
backcolor="Gray"></HeaderStyle>
<AlternatingItemStyle
backcolor="LightGray"></AlternatingItemStyle>
</asp:DataGrid>
</form>
</body>
</html>

"Vladimir Zheleznyak" <ik**@crlab.com> wrote in message
news:34**************************@posting.google.c om...
Hello,

Try to add this row at the beginning of your code:

<%@ Register TagPrefix="cr" Namespace="CoreLab.MySql"
Assembly="CoreLab.MySql, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=09af7300eec23701" %>


Nov 18 '05 #4

P: n/a
I had to make some other changes to my code to get this to work, so I'm
posting my new code in case anybody else needs this info in the future and
comes across this thread.

Thanks again for your help Vladimir!

My Code:

<%@ Page Language="C#" Debug="true" %>
<%@ Register TagPrefix="cr" Namespace="CoreLab.MySql"
Assembly="CoreLab.MySql, Version=2.40.1.0, Culture=neutral,
PublicKeyToken=09af7300eec23701" %>
<%@ import Namespace="CoreLab.MySql" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">

private void Page_Load(object sender, System.EventArgs e)
{

// create a connection
MySqlConnection oMySqlConn = new MySqlConnection();
oMySqlConn.ConnectionString = "User ID=<user id>;" +
"Password=<password>;" +
"Host=localhost;" +
"Database=<db name>;" +
"Direct=true;" +
"Protocol=TCP;" +
"Compress=false;";
string querystring = "select fields from table";

MySqlCommand mySqlCommand = new
CoreLab.MySql.MySqlCommand(querystring);

MySqlDataAdapter da = new CoreLab.MySql.MySqlDataAdapter();

DataSet ds = new DataSet();

mySqlCommand.Connection = oMySqlConn;

da.SelectCommand = mySqlCommand;

oMySqlConn.Open();
// fill dataset
da.Fill(ds, "Results");

// Attach DataSet to DataGrid
DataGrid1.DataSource = ds;
DataGrid1.DataBind();

oMySqlConn.Close();
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server">
<HeaderStyle font-bold="True" forecolor="White"
backcolor="Gray"></HeaderStyle>
<AlternatingItemStyle
backcolor="LightGray"></AlternatingItemStyle>
</asp:DataGrid>
</form>
</body>
</html>

"Vladimir Zheleznyak" <ik**@crlab.com> wrote in message
news:34**************************@posting.google.c om...
Hello,

Try to add this row at the beginning of your code:

<%@ Register TagPrefix="cr" Namespace="CoreLab.MySql"
Assembly="CoreLab.MySql, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=09af7300eec23701" %>

Nov 18 '05 #5

P: n/a
Note that the version value in my Register directive differs from Vladimir's
example. Be sure that you check your version information and put the right
value in there or the compiler won't like it.

-Erik
"Erik H." <er*********@wwireless.com> wrote in message
news:#D**************@TK2MSFTNGP11.phx.gbl...
I had to make some other changes to my code to get this to work, so I'm
posting my new code in case anybody else needs this info in the future and
comes across this thread.

Thanks again for your help Vladimir!

My Code:

<%@ Page Language="C#" Debug="true" %>
<%@ Register TagPrefix="cr" Namespace="CoreLab.MySql"
Assembly="CoreLab.MySql, Version=2.40.1.0, Culture=neutral,
PublicKeyToken=09af7300eec23701" %>
<%@ import Namespace="CoreLab.MySql" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>

<script runat="server">

private void Page_Load(object sender, System.EventArgs e)
{

// create a connection
MySqlConnection oMySqlConn = new MySqlConnection();
oMySqlConn.ConnectionString = "User ID=<user id>;" +
"Password=<password>;" +
"Host=localhost;" +
"Database=<db name>;" +
"Direct=true;" +
"Protocol=TCP;" +
"Compress=false;";
string querystring = "select fields from table";

MySqlCommand mySqlCommand = new
CoreLab.MySql.MySqlCommand(querystring);

MySqlDataAdapter da = new CoreLab.MySql.MySqlDataAdapter();

DataSet ds = new DataSet();

mySqlCommand.Connection = oMySqlConn;

da.SelectCommand = mySqlCommand;

oMySqlConn.Open();
// fill dataset
da.Fill(ds, "Results");

// Attach DataSet to DataGrid
DataGrid1.DataSource = ds;
DataGrid1.DataBind();

oMySqlConn.Close();
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataGrid id="DataGrid1" runat="server">
<HeaderStyle font-bold="True" forecolor="White"
backcolor="Gray"></HeaderStyle>
<AlternatingItemStyle
backcolor="LightGray"></AlternatingItemStyle>
</asp:DataGrid>
</form>
</body>
</html>

"Vladimir Zheleznyak" <ik**@crlab.com> wrote in message
news:34**************************@posting.google.c om...
Hello,

Try to add this row at the beginning of your code:

<%@ Register TagPrefix="cr" Namespace="CoreLab.MySql"
Assembly="CoreLab.MySql, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=09af7300eec23701" %>


Nov 18 '05 #6

P: n/a
I am having a similar problem. My code works fine for VB.net but gives
the error - "namespace name corelab not found" in C# code. I tried
using your code - added this at top of the page-

<%@ Register TagPrefix="cr" Namespace="CoreLab.MySql"
<BR>Assembly="CoreLab.MySql, Version=2.70.1.0, Culture=neutral,

<BR>PublicKeyToken=09af7300eec23701" %>

with correct version no. Still when I use using CoreLab.MySql; in my
.cs page, it throws error. Any idea?

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.