Skip a specified number of records in the dataset

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Skip
{
    public partial class Frm_Main : Form
    {
        public Frm_Main()
        {
            InitializeComponent();
        }

        private void Frm_Main_Load(object sender, EventArgs e)
        {
            QueryData(Convert.ToInt32(textBox1.Text));
        }

        private void button1_Click(object sender, EventArgs e)
        {
            QueryData(Convert.ToInt32(textBox1.Text));
        }

        QueryData is void Private (? int CNT)
        {
            String = Constr "the Data-GI7E47AND9R the Source WIN = \ the LS; Database = db_TomeTwo; the UID = SA; Pwd =;"; // get the connection string
            string sql = "select * from EmployeeInfo " ; // configured sql statement
            dataSet ds = new dataSet (); // create a dataset
            using (SqlConnection con = new SqlConnection ( conStr)) // create a data connection
            {
                the SqlCommand cmd = new new the SqlCommand (sql, CON); // Create Command object
                SqlDataAdapter sda = new SqlDataAdapter (cmd) ; // Create DataAdapter object
                sda.Fill (ds, "EmployeeInfo") ; // fill the dataset
            }
            IF (CNT CNT == null || <= 0) // if the parameter is empty, all the records taken
            {
                dataGridView1.DataSource = ds.Tables [ "EmployeeInfo"] ; // data source provided dataGridView1
            }
            the else // parameter specifies the number of records to skip
            {
                the try
                {
                    the IEnumerable <the DataRow> ds.Tables Query = [ "the EmployeeInfo"] AsEnumerable (. ) .Skip (cnt ?? 0); // set of query data using LINQ
                    dataGridView1.DataSource = query.CopyToDataTable (); // set the data source dataGridView1
                }
                the catch {}
            }
        }
    }
}

Guess you like

Origin blog.51cto.com/14536975/2438325