Friday, 23 September 2016

Bind Data from Database into Gridview :

Step 1:

Make sure the connection string declared properly both .Cs file & Aspx file and create a database into mysql and create table and insert some duplicate values .You wants to display ....


Web config  File :


<connectionStrings>
    <add name="constring" connectionString="Server=localhost;Database=Yourdatabasename;Uid=root;Pwd=password;pooling=false;" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>


Csharp File: (It places any where  you need connection string , either use both global and anywhere)


 MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["connec"].ConnectionString);

Step 2:

Add the new gridview in your aspx page and named it your own.The default name can be "Gridview1".First you need open the connection in the beginning and close at the end.


Cshrap page:


con.Open();
MySqlCommand cmd =new MySqlCommand("select empname,empaddress from employee where empid='"+ TextBox1.Text +"' ",con);
MySqlDataAdapter da=new MySqlDataAdapter(cmd);
DataSet ds=new DataSet();
da.Fill(ds);
GridView1.DataSource=ds;
GridView.DataBind();
con.Close();





How to create a simple Hello World website in ASP.NET MVC using Razor Syntax: (Note: I am using Visual Studio 2012 ) Step 1: ...