How to populate gridview with mysql?


Problem :

I just know how to populate gridview with 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#
Someone can teach me or give me some tutorial?



Solution :

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();
}

}

Mysql Tutorials

Mysql Howto..

How to include specific column elements in MySQL Select clause based on user's input in a PHP/HTML form?

MySQL How to obtain the MIN and MAX of the top 100 values in a table

How to transfer my MYSQL table to a derby database?

How to make login API in node.js using mysql database

How to save data from array (PHP) to MySQL table? (using MySQLi)

how to select only one value from more similiar values using mysql order by

how connect this table to MySQL

Hiding the decimal if .0 and showing zero if an integer

How to get the number of occurrence of each distinct value of GROUP CONCAT (php,mysql)

How can I find word matches from a string in a simple mysql/php words in string wordsolver app?

How to search for slash (\) in MySQL? and why escaping (\) not required for where (=) but for Like is required?

How do I replace/update all instances of every string in a column with matching values from another table?

how to do a MySQL query without creating temp tables?

How to pass AJAX results back to requester page

PHP + MySQL: How to select values from a checkbox

How do I ensure data consistency in this concurrent situation?

How to upload photo with text?

How to create a MySQL schema when deploying with Heroku (Express Server)

How to update unlimited form field form in database?

How to delete fields with bigger than a value in mysql

Magento: How to LEFT-JOIN 'catalog/category' fields to 'sales/order_item' collection?

How does Rails know where the MySQL database is?

How to get the highest value from a sum of values in php that is not in MySQL

How to use MYSQL's “AS” returned value inside WHERE clause?

Using Talend to extract HTML Search Pages into .txt files based on input keywords. How can I parse this data End-to-End and write it to MySQL?

Using PIP in a virtual environment, how do I install MySQL-python

how to handle url modifications php/mysql

How to change duplicate rows to unique values in mysql?

MySQL: How to find leaves in specific node

How to conditionally SELECT multiple columns with MySQL?