
本文共 5069 字,大约阅读时间需要 16 分钟。
���������������������������������������������GridView������������������������������������������������������������������������������������������������������������������������Oracle���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������CodeProject���������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������
������������������������������
1���������DataReader
2������������������������������������������DataReader
3������������������������������
4������������������������DataTable������������
5���������DataReader
6���������DataTable������������
������������������������������������������������������������������������DataReaderToDataTable���������������������������������
internal static DataTable DataReaderToDataTable( string sQuery, int iStart, int iEnd) { DataTable schematable = null ; DataTable dt = null ; SqlCommand cmdsql; SqlDataReader dr = null ; SqlConnection conn = null ; long icount = 0 ; try { // ������������������������������DataReader conn = new SqlConnection(ConnString); conn.Open(); cmdsql = new SqlCommand(sQuery, conn); dr = cmdsql.ExecuteReader(CommandBehavior.CloseConnection); schematable = dr.GetSchemaTable(); dt = new DataTable(); // Get the Schema of Tables Columns and its types, and load the same into DataTable. for ( int i = 0 ; i <= schematable.Rows.Count - 1 ; i ++ ) { DataRow dRow = schematable.Rows[i]; DataColumn column = new DataColumn(); column.DataType = System.Type.GetType(dRow[ " DataType " ].ToString()); column.AllowDBNull = (dRow[ " AllowDBNull " ].ToString() == " True " ? true : false ); column.ColumnName = dRow[ " ColumnName " ].ToString(); column.Caption = dRow[ " ColumnName " ].ToString(); dt.Columns.Add(column); // More DataTable property can be added as required. } if (iStart == 0 ) iStart = 1 ; if (iEnd == 0 ) iEnd = 1 ; icount = 1 ; // Loop the Reader which is executed till the Start and Variable, // Fetch and add the rows one by one to Data Table Till the End Count is reached. // Exit the loop and Return Datable. while (dr.Read()) { if (icount >= iStart && icount <= iEnd) { DataRow dRow = dt.NewRow(); for ( int i = 0 ; i <= dr.FieldCount - 1 ; i ++ ) { dRow[i] = dr.GetValue(i); } dt.Rows.Add(dRow); } else if (icount > iEnd) { break ; } icount = icount + 1 ; } } catch (SystemException ex) { throw ex; } finally { conn.Close(); conn.Dispose(); schematable.Dispose(); dr.Close(); dr.Dispose(); } return dt; }
������������������GridView������������������
private void BindData( int pageIndex) { int startRow; int endRow; startRow = (pageIndex * grdEmployee.PageSize) + 1 ; endRow = startRow + grdEmployee.PageSize - 1 ; ������������������ grdEmployee.DataSource = CustomPaging.Class.Common.DataReaderToDataTable(SelectQuery,startRow,endRow); grdEmployee.DataBind(); }
���������������������������������������������������������
发表评论
最新留言
关于作者
