Sample function to load gridview using sql

Sample function to load a normal gridview using sql

        protected void LoadGridViewUsingSQL()
            string connStr = "server= local);database=Northwind;uid=userid;pwd=password";
            SqlConnection sqlConn ;
            SqlCommand cmd = new SqlCommand();     
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);

            cmd.CommandText = "Ten Most Expensive Products";
            cmd.CommandType = CommandType.StoredProcedure;
            using (sqlConn = new SqlConnection(connStr))
                cmd.Connection = sqlConn;

            GridView1.DataSource = ds;

No comments:

Post a Comment

Keep ur coding aside.. Relax for some time..