📄 myitemlist.cs
字号:
using System;
using System.Collections;
using System.Data.OleDb;
using System.Data;
namespace Pagination
{
/// <summary>
/// MyItemList 的摘要说明。
/// </summary>
public class MyItemList
{
private static string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\study\Pagination\dbtest.mdb";
private string _connString;
private int _id;
private string _categoryID;
private string _itemID;
private string _itemTitle;
private string _itemDescription;
private string _bidsPrice;
private string _buyPrice;
private string _itemSubTitle;
public string ConnString
{
get{return _connString;}
set{_connString=value;}
}
public int ID
{
get { return _id; }
set { _id = value; }
}
public string CategoryID
{
get { return _categoryID; }
set { _categoryID = value; }
}
public string ItemID
{
get { return _itemID; }
set { _itemID = value; }
}
public string ItemTitle
{
get { return _itemTitle; }
set { _itemTitle = value; }
}
public string ItemDescription
{
get { return _itemDescription; }
set { _itemDescription = value; }
}
public string BidsPrice
{
get { return _bidsPrice; }
set { _bidsPrice = value; }
}
public string BuyPrice
{
get { return _buyPrice; }
set { _buyPrice = value; }
}
public string ItemSubTitle
{
get { return _itemSubTitle; }
set { _itemSubTitle = value; }
}
public MyItemList()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public MyItemList(string connString)
{
this.ConnString=connString;
}
/// <summary>
/// 获取数据库中纪录总数
/// </summary>
/// <returns></returns>
public int GetCount()
{
OleDbConnection conn = new OleDbConnection(this.ConnString);
int RecordCount = 0;
OleDbDataReader reader = null;
string sql = "select count(*) as counts from ItemList";
try
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, conn);
reader = cmd.ExecuteReader();
if (reader.Read())
{
RecordCount = Int32.Parse(reader["counts"].ToString());
}
reader.Close();
conn.Close();
return RecordCount;
}
catch (Exception ex)
{
conn.Close();
Console.WriteLine(ex.Message);
return 0;
}
}
/// <summary>
/// 获取数据库中所有纪录,并放入DataSet
/// </summary>
/// <returns></returns>
public ArrayList GetRecords()
{
ArrayList al = new ArrayList();
string sql = "select * from ItemList order by ID Desc";
OleDbConnection conn = new OleDbConnection(this.ConnString);
OleDbDataReader reader = null;
try
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, conn);
reader = cmd.ExecuteReader();
while (reader.Read())
{
MyItemList il = new MyItemList();
il.ID = int.Parse(reader["ID"].ToString());
il.CategoryID = reader["CategoryID"].ToString();
il.ItemID = reader["ItemID"].ToString();
il.ItemTitle = reader["ItemTitle"].ToString();
il.ItemDescription = reader["ItemDescription"].ToString();
il.BidsPrice = reader["BidsPrice"].ToString();
il.BuyPrice = reader["BuyPrice"].ToString();
il.ItemSubTitle = reader["ItemSubTitle"].ToString();
al.Add(il);
}
reader.Close();
conn.Close();
}
catch (Exception ex)
{
reader.Close();
conn.Close();
Console.WriteLine(ex.Message);
}
return al;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -