日期:2014-05-17 浏览次数:20824 次
public class TestCode
{
private static List<string> ids = new List<string>();
private static List<string> names = new List<string>();
private static string myConnstr;
private static OleDbConnection myconn; // 数据库连接
private static string mysql; // 数据库操作语句
private static OleDbCommand mycommand = new OleDbCommand();
private static string dbpath; // 数据库名
private static int InsertStartId;
// 初始化数据库.
private static void initdatabase()
{
dbpath = "oledb.mdb";
myConnstr =
@"Provider=Microsoft.Jet.OleDB.4.0;Data Source=" +
dbpath;
}
// 查询数据库
private static void findall()
{
ids.Clear();
names.Clear();
mysql = @"select id,user_name from users"; // 操作
using (myconn)
{
myconn = new OleDbConnection(myConnstr);
myconn.Open();
mycommand.CommandText = mysql;
mycommand.Connection = myconn;
OleDbDataReader myreader = mycommand.ExecuteReader();
int i = 0;
while (myreader.Read())// 读取
{
&n