Input a select statement for the SqlDataAdapter class, add the result to the DataSet result set in the form of rows through the Fill method, and then present the result to the user in the form of scroll below. The main program code is as follows. The Fill method of the SqlDataAdapter class is used to extract a piece of data from the query result and add it to the dataSet result set.
PublicDataSetdsResult (int currentIndex)
{
Int pageSize = 1;
String orderSQL = "SELECT * FROM t_People order by tb_PID ";
SqlDataAdapter adapter = new SqlDataAdapter (orderSQL, ConDB ());
DataSetdataSet = newDataSet ("t_People ");
Adapter. Fill (dataSet, currentIndex, pageSize, "t_People ");
ReturnDataSet;
} Link: For the ConDB () method, see section 21.3.1.
Obtain the total number of records in the table, which is used to identify the index value of the last information.
Public int Max ()
{
SqlCommandcmd = new SqlCommand ("select count (*) from t_people", ConDB ());
Return int. Parse (cmd. ExecuteScalar (). ToString ());
} Form loading event. Obtain the total number of rows through the Max method in the ClsDBControl class. The code for the LastNum program is as follows:
Private void FrmSelect_Load (object sender, EventArgs e)
{
ClsDB. ClsDBControl CDBLast = new OptDB. ClsDB. ClsDBControl ();
LastNum = CDBLast. Max ();
} The program code for displaying the "first" information is as follows:
Private void button#click (object sender, EventArgs e)
{
I = 0;
ClsDB. ClsDBControl cdb = new OptDB. ClsDB. ClsDBControl ();
DataSetdsNew = cdb. dsResult (I );
This. textBox1.Text = dsNew. Tables [0]. Rows [0] [0]. ToString ();
This. textBox2.Text = dsNew. Tables [0]. Rows [0] [1]. ToString ();
This. textBox3.Text = dsNew. Tables [0]. Rows [0] [2]. ToString ();
} The program code for displaying "previous" information is as follows:
Private void button2_Click (object sender, EventArgs e)
{
I-= 1;
If (I> = 0)
{
ClsDB. ClsDBControl cdb = new OptDB. ClsDB. ClsDBControl ();
DataSetdsNew = cdb. dsResult (I );
This. textBox1.Text = dsNew. Tables [0]. Rows [0] [0]. ToString ();
This. textBox2.Text = dsNew. Tables [0]. Rows [0] [1]. ToString ();
This. textBox3.Text = dsNew. Tables [0]. Rows [0] [2]. ToString ();
}
Else
{
I + = 1;
MessageBox. Show ("This is the first message ");
}
} The program code for displaying the "last" information is as follows:
Private void button4_Click (object sender, EventArgs e)
{
ClsDB. ClsDBControl cdb = new OptDB. ClsDB. ClsDBControl ();
DataSetdsNew = cdb. dsResult (LastNum-1 );
This. textBox1.Text = dsNew. Tables [0]. Rows [0] [0]. ToString ();
This. textBox2.Text = dsNew. Tables [0]. Rows [0] [1]. ToString ();
This. textBox3.Text = dsNew. Tables [0]. Rows [0] [2]. ToString ();
& Nbs