MySQL & Datagrid using C# - getting compile error

E

Erik H.

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>
 
V

Vladimir Zheleznyak

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" %>
 
E

Erik H.

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>
 
E

Erik H.

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
 
S

shivani

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
*-----------------------*
 

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,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top