Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to populate gridview with mysql?

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?

like image 608
Lai32290 Avatar asked Apr 20 '13 02:04

Lai32290


People also ask

How do I display the contents of a table in MySQL?

The first command you will need to use is the SELECT FROM MySQL statement that has the following syntax: SELECT * FROM table_name; This is a basic MySQL query which will tell the script to select all the records from the table_name table.

How do I show rows in a column in MySQL?

Display Row Values as Columns in MySQL Dynamically You can customize the above query as per your requirements by adding WHERE clause or JOINS. If you want to transpose only select row values as columns, you can add WHERE clause in your 1st select GROUP_CONCAT statement.

How do I select a view in MySQL?

The basic syntax for creating a view in MySQL is as follows: CREATE VIEW [db_name.] view_name [(column_list)] AS select-statement; [db_name.] is the name of the database where your view will be created; if not specified, the view will be created in the current database.


1 Answers

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

}
like image 94
Chetan Sanghani Avatar answered Oct 01 '22 21:10

Chetan Sanghani