Sir i want to use a gridview in visual studio and data is fatched from MySQL using where query using grid view
sir plz note why i want to use grid view becasue it has inbuild facility to edit and delete and select data
and i am familier with ASP.Net C#
so plz someone help me on orgent basis to fatch data from MySQL in gridview with where query
i have tried a lot but all has gone fail
Sachin SinghPosted Jun 20, 2021, 7:57 PM
please explain your exact issue, in order to fetch data or to communicate with MySql you need to install,
MySql Connector for .Net, assuming that you have already installed the correct version of MySql Connector/Net
here is the code
using System;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
public void BindGrid
{
string connStr = "server=localhost;user=root;database=world;port=3306;password=******";
Using(MySqlConnection conn = new MySqlConnection(connStr))
{
Console.WriteLine("Connecting to MySQL...");
conn.Open();
string sql = "SELECT * FROM Country WHERE Continent='Oceania'";
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataReader rdr = cmd.ExecuteReader();
GridView1.DataSource= rdr;
GridView1.DataBind();
}
}
Namespaces used:-