asp.net连接mysql数据库
Mysql的connector/net5.0下载地址:
http://dev.mysql.com/get/Downloads/Connector-Net/mysql-connector-net-5.0.6.zip/from/pick
安装好以后,
点属性,然后点查找目标,点向上一层目录,找到Binaries\.NET 2.0,然后将这个文件复制到你的工程目录下,一般这样的DLL文件会保存到bin目录下.
在代码页里输入using Mysql.Data.MysqlClient;然后再在Page_Load函数里写MysqlConnection,在单词写到一半时提示就出来了,下面的就不用写了吧?都已经出现”代码智能完成了”,随便写一段代码试试就可以了,和Sqlserver完全相似.
下面提供两段代码供参考,一个代码页
default2.aspx.cs下的代码:
C#代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string query = "select * from guestbook";
MySqlConnection myConnection = new MySqlConnection("server=localhost;user id=root;password=;database=guestbook");
MySqlCommand myCommand=new MySqlCommand(query,myConnection);
myConnection.Open();
myCommand.ExecuteNonQuery();
MySqlDataReader myDataReader = myCommand.ExecuteReader();
string bookres="";
while (myDataReader.Read()==true)
{
bookres+=myDataReader["id"];
bookres+=myDataReader["user"];
bookres += myDataReader["pass"];
}
myDataReader.Close();
myConnection.Close();
lb1.Text = bookres;
}
}
1、下载MySQL数据库,地址:http://www.mysql.com/,大小只有几十个兆而已,安装很方便,接提示即可。
2、MySQL安装后默认是没有客户端工具的(像SQLServer的企业管理器,查询分析器等),只是一个服务器存储数据,为了方便你要再下载一个客户端工具,有很多,推荐使用SQL Manager for MySQL,简洁小巧,功能也强大。下载:http://www.sqlmanager.net/en/products/mysql/manager/download
3、ASP.NET连接MySQL需要一个组件(.net本身不提供访问MySQL的驱
相关文档:
第一种方法:
通过URL链接地址传递
send.aspx:
protected void Button1_Click(object sender, EventArgs e)
{
Request.Redirect("Default2.aspx?username=honge");
}
receive.aspx:
string user ......
客户端验证方式:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
&nbs ......
1. 当不需要使用Session的时候请关闭
关闭Session当不需要使用的时候
• 若要禁用页的会话状态,请将@ Page 指令中的EnableSessionState 属性设置为false。例如, <%@ Page EnableSessionState="false" %>。
• 注意如果页需要访问会话变量,但不打算创建或修改它们,则将 ......
The vs2008 and vs2010 don't support the generation LINQ to SQL business objects from a MySQL database, if you drop a MySql table to a Linq to Sql Class, it will popup a "The selected object(s) use an unsupported data provider" error.
Generation tool DBLinq
DbLinq is a LINQ to SQL data co ......
ASP连接MySQL数据库的方法
ASP等语言连接mysql数据库,可以通过安装mysql的ODBC驱动,通过配置ODBC数据源,连接并操作数据库。
mysql odbc 3.51版
下载地址:
http://dev.mysql.com/downloads/connector/odbc/3.51.html
<%
'测试读取MySql数据库的内容
strconnection="driver={mysql odb ......