Sunday, 24 September 2017

How to export From sql records to data Grid view

Database to Data Grid view:


            string connectionString = null; //connection string
            string sql = null; //query from db

            connectionString = "Data Source=LAB6-168;Initial Catalog=schoolm;User ID=sa;Password=aptech";
            SqlConnection cnn = new SqlConnection(connectionString); //con object
            cnn.Open(); //coneection open form db
            sql = "SELECT * FROM student"; //query
            SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn); //reads all records from db
            DataSet ds = new DataSet();
            dscmd.Fill(ds);

            dataGridView1.DataSource = ds.Tables[0];

No comments:

Post a Comment

Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...