如何使用“下一步"按钮显示下一条记录? [英] how To show next record by using Next Button?
本文介绍了如何使用“下一步"按钮显示下一条记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我的表单中有5个文本框
id(int)
代码(int)
发件人(字符串)
接收器(字符串)
正文(字符串)
(所有这些文本框都来自数据库...)
如何使用下一个按钮显示下一条记录,
以及如何显示我正在使用上一步"按钮的先前记录?
hi all
i have 5 text box in my form
id(int)
code(int)
sender(string)
receiver(string)
body(string)
(All these textboxes are comming from Databases...)
how To show next record i am using Next Button,
and how To Show previous record I am using Previous Button?
推荐答案
使用 ^ ]
您应该使用 MoveNext [ C#2.0中的BindingSource和BindingNavigator [
Use a BindingSource[^]
You should use the MoveNext[^] to move to the next record.
Create a DataSet containing a DataTable for your data.
Bind the DataTable to a BindingSource, and then bind the controls to their respective fields through the BindingSource. This can be done using the design tools in Visual Studio.
The following article may be of interest:
BindingSource and BindingNavigator in C# 2.0[^]
Regards
Espen Harlinn
这取决于您访问数据库的方式,但是如果我假设整数"id"是自动递增的,那么在上一和下一个词时,您的意思是一个较低的id", 较高的ID";并假设您正在使用SQLReader,则:
1)将具有ID的TextBox转换为int:
It depends on how you are accessing the database, but if I assume that the integer "id" is auto-incrementing and by previous and next you mean "one lower id" and "one higher id"; and also assume you are using an SQLReader then:
1) Convert your TextBox with the id to an int:
int id = int.Parse(myIdTextBox.Text);
2)准备一个SQL命令以使用该值:
2) Prepare an SQL command to use that value:
string sql = "SELECT id, code, sender, receiver, body FROM MyTable WHERE id>@ID";
SqlCommand com = new SqlCommand(sql, con);
com.Parameters.AddWithValue("@ID", id);
SqlDataReader r = com.ExecuteReader();
第一个记录将是数据库中的下一个ID.
您可以对上一个"执行类似的过程,但要记住更改返回记录的顺序!
The first record will be the next id in the database.
You can do a similar process for "previous", but remember to change the order of the records returned!
这篇关于如何使用“下一步"按钮显示下一条记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文