zoukankan      html  css  js  c++  java
  • C# 逐条查询显示数据

    逐条查询显示数据主要用到了 SqlDataAdapter.Fill 的重载方法

    SqlDataAdapter.Fill(DataSet,intStartRecord,intNumRecords,“TableName”)

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    
    namespace MoveNote
    {
        public partial class Form1 : Form
        {
            static int count;
            private int currentRow = 0;
            SqlConnection connection = new SqlConnection("server=.;database=db_09;uid=sa;pwd=test");
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                using (SqlCommand command = new SqlCommand("select count(员工编号) from 员工表", connection))
                {
                    connection.Open();
                    count = (int)command.ExecuteScalar();
                }
            }
    
            private void btnFirst_Click(object sender, EventArgs e)
            {
                currentRow = 0;
                SetTextBoxInfo(currentRow);
            }
    
            private void btnPreview_Click(object sender, EventArgs e)
            {
                currentRow -= 1;
                if (currentRow < 0)
                {
                    currentRow = 0;
                    MessageBox.Show("当前已经为第一条记录!");
                    return;
                }
                SetTextBoxInfo(currentRow);
            }
    
            private void btnNext_Click(object sender, EventArgs e)
            {
                currentRow++;
                if (currentRow >= count)
                {
                    currentRow = count - 1;
                    MessageBox.Show("当前已经为最后一条记录!");
                    return;
                }
                SetTextBoxInfo(currentRow);
            }
    
            private void btnEnd_Click(object sender, EventArgs e)
            {
                currentRow = count-1;
                SetTextBoxInfo(currentRow);
            }
    
            private DataSet  DtResult(int i)
            {
                using (SqlDataAdapter adp = new SqlDataAdapter())
                {
                    adp.SelectCommand = new SqlCommand("select * from 员工表", connection);
                    DataSet ds = new DataSet();
                    adp.Fill(ds,i,1, "员工表");
                    return ds;
                }
            }
    
            private void SetTextBoxInfo(int i)
            {
                DataSet dsNew = DtResult(i);
                txtID.Text = dsNew.Tables["员工表"].Rows[0][0].ToString();
                txtName.Text = dsNew.Tables["员工表"].Rows[0][1].ToString();
                txtSalary.Text = dsNew.Tables["员工表"].Rows[0][2].ToString();
                txtPJ.Text = dsNew.Tables["员工表"].Rows[0][3].ToString();
            }
        }
    }

  • 相关阅读:
    【洛谷 P5357】 【模板】AC自动机(二次加强版)(AC自动机,差分)
    【洛谷 P1659】 [国家集训队]拉拉队排练(manacher)
    【洛谷 P3224】 [HNOI2012]永无乡(Splay,启发式合并)
    HNOI2019退役祭
    类欧几里得算法模板
    乘法逆元模板
    $Luogu$ $P3130$ $[USACO15DEC]$ 计数 $Counting$ $Haybales$
    $Luogu$ $P2746$ $[USACO5.3]$ 校园网 $Network$ $of$ $Schools$
    $Luogu$ $P2243$ 电路维修
    $Luogu$ $P4667$ $[BalticOI$ $2011$ $Day1]$ 打开灯泡 $Switch$ $the$ $Lamp$ $On$
  • 原文地址:https://www.cnblogs.com/wenjie0904/p/9906382.html
Copyright © 2011-2022 走看看