可以進行sql語句進行設定:
1.先新建乙個窗體,乙個datagridview控制項、兩個label控制項、兩個button控制項
2.**如下:
usingview codesystem;
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
_2012_4_7
static
string str = "
server=.;database=shudb;uid=sa;pwd=accp";
sqlconnection conn = new
sqlconnection(str);
dataset
set = new
dataset();
sqldataadapter adapter;
int index = 0; //
sql語句中的索引
int yeshu = 1; //
int sum = 0; //
總頁碼
//載入前6行資料
private
void form1_load(object
sender, eventargs e)
this.label2.text = "
總頁數" +sum.tostring();
conn.close();
}//private
void button1_click(object
sender, eventargs e)
//頁數是0則返回
index--;
yeshu--;
this.label1.text = "
第" + yeshu.tostring() + "頁"
;
string sql = @"
select top 6 * from shu where shuid not in
(select top (6*
" + index + "
) shuid from shu)";
getdataset(sql);
}//private
void button2_click(object
sender, eventargs e)
index++;
yeshu++;
this.label1.text = "
第" + yeshu.tostring()+"頁"
;
string sql = @"
select top 6 * from shu where shuid not in
(select top (6*
"+index+"
) shuid from shu)";
getdataset(sql);
}//繫結
public
void getdataset(string
sql)
adapter.fill(
set, "
stu"
);
this.datagridview1.datasource = set.tables["
stu"
]; }}}
c 控制項 datagridview
datagridview繫結資料,同樣可以檔案讀取資料 迴圈賦值新增到datatable private void datablind datagridview內新增其他控制項 可新增button datagridviewbuttoncolumn checkbox datagridviecheckb...
應有dataGridView控制項
using system.data.sqlclient namespace usedatagridview string strcon server localhost user id sa pwd database my 定義資料庫連線字串 sqlconnection sqlcon 宣告資料庫連線...
DataGridView控制項的使用
1 資料繫結 下面將介紹用datatable對datagridview控制項進行繫結。首先得到datatable dt,dt中的列為 id pname short name 其次 設定datagridview控制項 dgvproductname 的列,如下圖所示。注意 列的個數要與datatable...