using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MySqlConnection DBConn = new MySqlConnection("Data Source=localhost;Database=SD200_AUTO_TEST;user ID=root ; password=root1234;port=;  charset=gb2312;");        try
        {            DBConn.Open();
        }
        catch (Exception ex)
        {
        }
        finally 
        {
            DBConn.Close();
            DBConn.Dispose();
        }    }    public MySqlConnection GetConnection() 
    {        string connStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
        MySqlConnection mysqlConn = new MySqlConnection(connStr);
        return sqlConn;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        MySqlConnection mysqlConn = GetConnection();
        mysqlConn.Open;
        string mysqlStr = "select * ";
            MySqlCommand mysqlCom=new MySqlCommand (mysqlStr ,mysqlConn );
            MySqlDataAdapter dr = mysqlConn.Execute();
            GridView1.DataBind();
            dr.Close();
            mysqlConn.Close();    }
}

解决方案 »

  1.   

    page_load里的那段没用吧删掉sql语句  string mysqlStr = "select * from 表名";SqlDataAdapter da = new SqlDataAdapter(sql, conn);DataSet ds = new DataSet();
    da.Fill(ds);错的一塌糊涂
      

  2.   

    数据库用的是MYSQL  查询语句没写完的  
      

  3.   

    接楼上的:
    this.GridView1.DataSource=ds.Tables[0];
    this.GridView1.DataBind();
      

  4.   

    错误太多了,SQL语句有错了,GridView1没有得到数据源,里面不会有数据。