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?
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.
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.
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.
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With