C#.NETÁ¬½Ómysql·½·¨
Ò»¡£ mysql.data.dll¿½±´µ½binÏÂÃæ²¢ÒýÓÃÒ»ÏÂ
using MySql.Data.MySqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string myConnectionString = "Database=test;Data Source=localhost;User Id=root;Password=admin";
MySqlConnection mycn = new MySqlConnection(myConnectionString);
try
{
mycn.Open();
Response.Write("<mce:script type="text/javascript"><!--
alert('Á¬½Ó³É¹¦')
// --></mce:script>");
}
catch (Exception ex)
{
Response.Write("<mce:script type="text/javascript"><!--
alert(" ex.ToString() ")
// --></mce:script>");
}
}
}
Ò²¿ÉÒÔÅäÖÃapp.config (web.config):
<appSettings>
<add key="Con" value="Provider=MySQLProv;Data Source=test;User Id=root;Password=admin;pooling=false;CharSet=utf8;port=3306"/>
</appSettings>
¶þ¡£ÒªÌí¼Ó¶ÔMySql.Data.dllµÄÒýÓá£
Á¬½Ó£º
string connStr = "server=localhost;user id=root; password=; database=aa; pooling=false";//
Á¬½Ó×Ö·û´®
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º
MySqlConnection conn = new MySqlConnection( connStr );//¹¹ÔìÊý¾Ý¿âÁ¬½Ó
try
{
conn.Open();//´ò¿ªÁ¬½Ó
MySqlCommand cmd = new MySqlCommand("select * from list",conn);//¹¹Ôì²éѯÃüÁî
this.DataGrid1.DataSource=cmd.ExecuteReader();//Ö´Ðвéѯ£¬·µ»ØÒ»¸öDataReader£¬ÉèÖÃDataGrid1µÄÊý¾ÝԴΪ¸ÃDataReader
Ïà¹ØÎĵµ£º
MySQL ×Ö·û´®½ØÈ¡º¯Êý£ºleft(), right(), substring(), substring_index()¡£»¹ÓÐ mid(), substr()¡£ÆäÖУ¬mid(), substr() µÈ¼ÛÓÚ substring() º¯Êý£¬substring() µÄ¹¦Äܷdz£Ç¿´óºÍÁé»î¡£
1. ×Ö·û´®½ØÈ¡£ºleft(str, length)
mysql> select left('sqlstudy.com', 3);
+-------------------------+
| left('sq ......
£ÛתÔØ£ÝMySQL£ºMySQL ´´½¨´æ´¢¹ý³Ì£¨MySQL 5.0£©
2008-09-11 22:14
MySQL ´æ´¢¹ý³ÌÊÇ´Ó MySQL 5.0 ¿ªÊ¼Ôö¼ÓµÄй¦ÄÜ¡£´æ´¢¹ý³ÌµÄÓŵãÓÐÒ»Âá¿ð¡£²»¹ý×îÖ÷ÒªµÄ»¹ÊÇÖ´ÐÐЧÂʺÍSQL ´úÂë·â×°¡£ÌرðÊÇ SQL ´úÂë·â×°¹¦ÄÜ£¬Èç¹ûûÓд洢¹ý³Ì£¬ÔÚÍⲿ³ÌÐò·ÃÎÊÊý¾Ý¿âʱ£¨ÀýÈç PHP£©£¬Òª×éÖ¯ºÜ¶à SQL Óï¾ä¡£ÌرðÊÇÒµÎñÂß¼¸´ÔÓµÄʱº ......
³£³£Óöµ½´óÊý¾ÝÁ¿Æµ·±¶ÁдÊƱػᵼÖ·þÎñÆ÷µÄÐÔÄÜϽµ¡£ÏÂÃæ¼Ç¼һ϶ÔmysqlµÄÓÅ»¯ÅäÖÃ
1.Ê×ÏȹرÕauto commit¡£
2.¶ÔÓÚÊý¾Ý±íʹÓÃInnoDB¡£
3.¹Ø±ÕÍâ¼üÔ¼Êø¡£
4.²ÉÓöàÖµ²åÈë“INSERT INTO ±íÃû VALUES (1,2), (5,5), ...;” Èç¹ûÓдóÁ¿²¢·¢¿ÉÒÔÓøü¸ÄINSERT INTOΪ INSERT DELAYED INTO¿ÉÒÔÔڳ̶ÈÉϽ⾠......
Ö÷Ìå¼Ü¹¹
¡¡¡¡¸÷ƵµÀ·Ö±ðλÓÚ²»Í¬µÄWeb Project(¾ßÓжÀÁ¢µÄ¶þ¼¶ÓòÃû)£¬²¢½«ËùÓеÄÒµÎñÂß¼ÒÔ¼°Êý¾Ý·ÃÎʹ¦ÄÜ·â×°³ÉClass Library£¬ËùÓÐƵµÀ¹²ÓÃÕâ¸öClass Library¡£
¡¡¡¡ÏÂÃæÏêϸ½éÉÜʵÏÖ·½·¨¡£
¡¡¡¡¼ÙÉèÍøÕ¾ÓÐÈý¸öƵµÀ£¬ÐÂÎÅ¡¢ÂÛ̳ÒÔ¼°²©¿Í£¬¶ÔÓ¦µÄ¶þ¼¶ÓòÃûΪ"news"¡¢"forum"¡¢"blog"¡£³ ......