본문 바로가기
MySql

MySQL GridView를 mysql로 ​​채우는 방법은 무엇입니까?

by 베이스 공부 2021. 1. 3.
반응형

Gridview를 asp : SqlDataSource 로 채우는 방법을 알고 있습니다.
But I have a column of TemplateField in my gridview, when I need modify my SQL for alter grid content, I lose my TemplateField, so I think learn populate my gridview with C#
누군가 저를 가르치거나 튜토리얼을 줄 수 있습니까?

 

해결 방법

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.Common;
using MySql.Data.MySqlClient;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Data;

public partial class viewAdmin : System.Web.UI.Page
{
    String MyConString = "SERVER=localhost;" +
                "DATABASE=databasename;" +
                "UID=root;" +
                "PASSWORD=;";
protected void Page_Load(object sender, EventArgs e)
{

        MySqlConnection conn = new MySqlConnection(MyConString);
        MySqlCommand cmd = new MySqlCommand("SELECT * FROM tablename;", conn);
        conn.Open();
        DataTable dataTable = new DataTable();
        MySqlDataAdapter da = new MySqlDataAdapter(cmd);

        da.Fill(dataTable);


        GridVIew.DataSource = dataTable;
        GridVIew.DataBind();
}

}

 

참조 페이지 https://stackoverflow.com/questions/16115985

 

 

반응형

댓글