C#远程访问Linux(Ubuntu)或Windows的MySQL数据库(4)

这里就简单写一个对方存在的数据库(information_schema是默认存在的),这里用的是asp

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

using System.Data;
using System.Data.Odbc;

namespace Help
{
   
publicpartialclass WebForm2 : System.Web.UI.Page
    {
       
protectedvoid Page_Load(object sender, EventArgs e)
        {
           
string strconn ="Driver={MySQL ODBC 3.51 Driver};Server=192.168.1.102;Database=information_schema;User=Lucy; Password=123;Option=3;chartset=utf8";
           
string sql ="select * from CHARACTER_SETS";
            OdbcConnection myConnection
=new OdbcConnection(strconn);
            OdbcCommand myCommand
=new OdbcCommand(sql, myConnection);
            myConnection.Open();

           
//DropDownList1.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
           
//DropDownList1.DataTextField = "name";
           
//DropDownList1.DataValueField = "id";
           
//DropDownList1.DataBind();
            OdbcDataAdapter sda =new OdbcDataAdapter();
            sda.SelectCommand
= myCommand;
            DataSet ds
=new DataSet();
            sda.Fill(ds);
            GridView1.DataSource
= ds;
            GridView1.DataBind();
           
            myConnection.Close();
        }
    }
}

5、远程访问后,运行效果:

C#远程访问Linux(Ubuntu)或Windows的MySQL数据库

6、总结

6.1、操作系统上大部分有一些共性,其操作思想是可以移植的。

6.2、如何看懂相应的配置文件说明是很重要的。

6.3、命令行多少也得学一些。至少打开‘服务’的时候,输入services.msc,就可以打开服务了。

6.4、抽象出自己可理解和实际相结合的模型是挺重要的。

6.5、(举一反三)是不是只有C#行呢?VB、Java这些不行吗?那linxu下ruby、php去访问windows的SQL呢?具体情况,就只有实践能证明了。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwspzf.html