Connecting to database mysql

Reply Forum
Forum postjohn @ 2011-11-06 10:55:44
ReplyReply to
thius code is giving me an error cs103 can some
one help
thanks alot

using System.Data.Odbc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;



public partial class _Default : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
try
{
using (OdbcConnection connection = new OdbcConnection(ConfigurationManager.ConnectionStrings["MySQLConnStr"].ConnectionString))
{
connection.Open();
using (OdbcCommand command = new OdbcCommand("SELECT name FROM test_users", connection))
using (OdbcDataReader dr = command.ExecuteReader())
{
while (dr.Read())
Response.Write(dr["name"].ToString() + "<br />");
dr.Close();
}
connection.Close();
}
}
catch (Exception ex)
{
Response.Write("An error occured: " + ex.Message);
}
}
}











© net-tutorials.com 2006 - 2012

MailContact net-tutorials.com