这是我曾经练手的一个程序中的代码。增删改查基本都来了。这里提醒一句,使用access数据库的时候,一定要注意尽量不用关键字(有些关键字估计你压根都不知道是关键字,比如user,不然报的错会让你莫名其妙)。但是不是不能用,加个中括号就好。我的access数据库是加密了的,aapconfig文件的代码如下:<xml version="10" encoding="utf-8" >
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="DataBaseOwner" connectionString="dbo"/>
<add name="XinXingConnectionString" connectionString=
"Provider=MicrosoftJetOLEDB40;Data Source=db2mdb;User ID=Admin;Jet OLEDB:Database Password=密码"
providerName ="MicrosoftJetOLEDB40"/>
</connectionStrings>
<appSettings>
<add key="DBType" value="Sql"/>
</appSettings>
</configuration>具体增删改查的代码如下:using System;
using SystemCollectionsGeneric;
using SystemText;
using SystemDataOleDb;
using SystemConfiguration;
using XinXingModels;namespace XinXingDAL
{
public class ProgramService
{
#region Private Members
//从配置文件中读取数据库连接字符串
private readonly string connString =
ConfigurationManagerConnectionStrings["XinXingConnectionString"]ToString();
private readonly string dboOwner =
ConfigurationManagerConnectionStrings["DataBaseOwner"]ToString();
#endregion /// <summary>
/// 查询所有账户信息
/// </summary>
/// <returns></returns>
public IList<Account> SearchAllRemarks()
{
List<Account> account = new List<Account>();
using (OleDbConnection conn = new OleDbConnection(connString))
{
OleDbCommand objCommand = new OleDbCommand("select from Account", conn);
connOpen();
OleDbDataReader objReader = objCommandExecuteReader();
while (objReaderRead())
{
Account a = new Account();
aId = ConvertToInt32(objReader["ID"]);
aRemarks = ConvertToString(objReader["Remarks"]);
aLoginID = ConvertToString(objReader["LoginID"]);
aPwd = ConvertToString(objReader["Pwd"]);
aTwoPwd = ConvertToString(objReader["TwoPwd"]);
aType = ConvertToString(objReader["Type"]);
accountAdd(a);
}
objReaderDispose(); connClose();
connDispose();
}
return account;
}
/// <summary>
/// 根据ID和备注查询相关信息
/// </summary>
/// <param name="id"></param>
/// <param name="remarks"></param>
/// <returns></returns>
public IList<Account> SelectInfoByRemarksAndID(int id, string remarks)
{
List<Account> account = new List<Account>();
using (OleDbConnection conn = new OleDbConnection(connString))
{
Account a = new Account();
string sql = stringFormat("select LoginID,Pwd,TwoPwd,Type from Account Where Id={0} and remarks='{1}'", id, remarks);
OleDbCommand objCommand = new OleDbCommand(sql, conn);
connOpen();
OleDbDataReader objReader = objCommandExecuteReader();
if (objReaderRead())
{
aLoginID = ConvertToString(objReader["LoginID"]);
aPwd = ConvertToString(objReader["Pwd"]);
aType = ConvertToString(objReader["Type"]);
aTwoPwd = ConvertToString(objReader["TwoPwd"]);
accountAdd(a);
}
}
return account;
}
/// <summary>
/// 查询所有备忘录
/// </summary>
/// <returns></returns>
public IList<Notepad> SearchAllInfoFromNotepad()
{
List<Notepad> notepad = new List<Notepad>();
using (OleDbConnection conn = new OleDbConnection(connString))
{
OleDbCommand objCommand = new OleDbCommand("select from Notepad", conn);
connOpen();
OleDbDataReader objReader = objCommandExecuteReader();
while (objReaderRead())
{
Notepad n = new Notepad();
nId = ConvertToInt32(objReader["ID"]);
nTime = ConvertToDateTime(objReader["Times"]);
nContent = ConvertToString(objReader["Content"]);
notepadAdd(n);
}
objReaderDispose();
connClose();
connDispose();
}
return notepad;
}
/// <summary>
/// 将备忘录插入
/// </summary>
/// <returns></returns>
public int InsertAllInfoIntoNotepad(string note)
{
int id;
using (OleDbConnection conn = new OleDbConnection(connString))
{
string sql = stringFormat("insert into Notepad(content) values('{0}')", note);
OleDbCommand objCommand = new OleDbCommand(sql, conn);
connOpen();
id = objCommandExecuteNonQuery();
}
return id;
}
/// <summary>
/// 查询最后一条记录
/// </summary>
/// <returns></returns>
public string SelectLastNotepad()
{
string message = "\n";
using (OleDbConnection conn = new OleDbConnection(connString))
{
string sql = stringFormat("SELECT top 1 from notepad order by ID desc");
OleDbCommand objCommand = new OleDbCommand(sql, conn);
connOpen();
OleDbDataReader objReader = objCommandExecuteReader();
while (objReaderRead())
{
message += ConvertToDateTime(objReader["Times"]) + "\n";
message += ConvertToString(objReader["Content"]);
}
}
return message;
} public int InsertAccount(string loginID, string pwd,string twoPwd,string remarks,string type)
{
int id;
using (OleDbConnection conn = new OleDbConnection(connString))
{
string sql = stringFormat("insert into Account(LoginID,Pwd,TwoPwd,Remarks,Type) values('{0}','{1}','{2}','{3}','{4}')", loginID, pwd, twoPwd, remarks, type);
OleDbCommand objCommand = new OleDbCommand(sql, conn);
connOpen();
id = objCommandExecuteNonQuery();
}
return id;
}
}}
aess数据库入门教程主要是以Aess2010为平台,全面而又详细地介绍Aess2010的各个知识点及其 *** 作方法。,通过各个不同的版块来具体学习aess数据库基础知识:
1、数据库基本概述:包括了关系数据库基础、数据库的基础知识、数据模型及关系数据库、关系运算、实体模型、关系规范化基础、数据库设计基础、Aess简介等。
2、数据库和数据表:包括了数据库 *** 作、创建数据表、设置字段“常规”属性、建立数据表之间的关系、数据表的基本 *** 作、调整数据表的外观。
3、查询的基本概念:包括了查询简介、创建选择查询、创建计算查询、创建特殊用途查询、创建 *** 作查询、结构化查询语言等。
4、窗体:包括了认识窗体、创建窗体、窗体控件、定制系统控制窗体等。
5、报表:包括了报表的基本概念、创建报表、报表设计、报表的高级设计等。
通过等等不同章节的学习,逐步了解aess数据库的基础理论性知识,然后学习领悟实际 *** 作知识及技巧。
26B 需求分析是软件设计的定义阶段,设计求精是结构化程序设计的原则之一,B的答案是数据库设计的七个步骤之三。
27B 扩展名
28A 专业关系运算;选择、投影、连接。传统的集合运算:并、交、差。概念题
29A
30B 3种基本运算:选择、投影、连接。
31D
32D
33D
34D
35D
36B
37B
38B
39A
40A
41A
42,C
43D 数据独立性指数据和程序间互不依赖。
44B
45D
46B
47C
无48题
49D
50A
全是基本概念题,只要掌握了概念即可,全考察基本的概念识记,没有难度。
建议多看看书。
以上就是关于寻找c#对access *** 作的示例全部的内容,包括:寻找c#对access *** 作的示例、access数据库入门教程是怎样的(access数据库怎么用)、Access理论知识等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)