每次单击按钮到网格时,如何从数据库中检索值的范围 [英] How to retrieve a range of values from database in each click of a button to a grid

查看:72
本文介绍了每次单击按钮到网格时,如何从数据库中检索值的范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在表单中每次单击按钮时从数据库中检索一定范围的值,并将其显示在网格中

How to retrieve a range of values from database in each click of a button in the form and display them in a grid

推荐答案

(如果您有SQL表)像:
表1
int id
varchar文字

上课
if you have an SQL table like:
Table1
int id
varchar text

make a class
class Table1
{
int id;
String text;
getId();
getText();

void selectRow(int id)
{
SQLConnection sql = new SQLConnection("connectionString");
//this query is easy, but using parameters is safer
string query = "select * from Table1 where id= "+id.ToString();
//use SQLReader
if(read)
{
this.id = ???
this.text = ???
}

static List<Table1> selectAll()
{
List<Table1> list = new List<Table>();
SQLConnection sql = new SQLConnection("connectionString");
//this query is easy, but using parameters is safer
string query = "select * from Table1";
//use SQLReader
Table1 tmp;
while(read)
{
tmp= new Table1();
tmp.id = ???
tmp.text = ???

list.Add(tmp);
}

}

}//class end

form:
init()
{
listview.AddColumn("id",50);
listview.AddColumn("text",100);
}
fillListView()
{
List<Table1> tList = new List<Table1>();
tlist = Table1.selectAll();
//add to list view
}


这篇关于每次单击按钮到网格时,如何从数据库中检索值的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆