C#操作Access类
Re
using System;
using System.Data;
using System.Data.OleDb;
namespace AccessDb
{
/**//// <summary>
/// AccessDb 的摘要说明,以下信息请完整保留
/// 请在数据传递完毕后调用Close()方法,关闭数据链接。
/// </summary>
public class AccessDbClass
{
变量声明处#region 变量声明处
public OleDbConnection Conn;
public string ConnString;//连接字符串
#endregion
构造函数与连接关闭数据库#region 构造函数与连接关闭数据库
/**//// <summary>
/// 构造函数
/// </summary>
/// <param name="Dbpath">ACCESS数据库路径</param>
public AccessDbClass(string Dbpath)
{
ConnString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
ConnString += Dbpath;
Conn = new OleDbConnection(ConnString);
Conn.Open();
}
/**//// <summary>
/// 打开数据源链接
/// </summary>
/// <returns></returns>
public OleDbConnection DbConn()
{
Conn.Open();
return Conn;
}
/**//// <summary>
/// 请在数据传递完毕后调用该函数,关闭数据链接。
/// </summary>
public void Close()
{
Conn.Close();
}
#endregion
数据库基本操作#region 数据库基本操作
/**//// <summary>
/// 根据SQL命令返回数据DataTable数据表,
/// 可直接作为dataGridView的数据源
/// </summary>
/// <param name="SQL"></param>
/// <returns></returns>
public DataTable SelectToDataTable(string SQL)
{
OleDbDataAdapter adapter = new OleDbDataAdapter();
OleDbCommand command = new OleDbCommand(SQL, Conn);
adapter.SelectCommand = command;
DataTable Dt = new DataTable();
adapter.Fill(Dt);
相关文档:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace 将枚举作为键值的形式存储
{
enum Myenum
{
First=3,
Second ......
根据宽度来决定显示的字符串长度 (C#,VS2005)
如果 lable长度固定但字符串长度可变,如果超过了lable显示的长度时,希望用 ...代替剩下的字符,这时需要一个函数
Graphics.MeasureString
具体代码如下
public string Abbreviation(string str)
{
&nbs ......
完善了“如何在C#中使用Win32和其他库”中关于EnumDesktops()函数的回调代码,可运行。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
delegate bool EnumDesk ......
通过一个实际的例子来介绍。其中重载==,!=,Equal,GetHashCode函数。
public class Record
{
public string[] arr = null;
public bool hasEqual = false;
//重载一个下标运算符号
public string this[int index]
{
get
{
return arr[index];
}
set
{
arr[index] = value;
}
}
public override int GetHas ......
function loginNull()
{
if (document.form1.txtName.value =="")
{
//alert("请填写您的用户名!");
WebForm1.show("用户名错误,不能为空").value;
//alert("请填写您的用户名!");
document.form1.txtName.focus();
return false;
}
var filter=/^s*[.A-Za-z0-9_-]{5,15}s*$/;
if (!filter.test(document.form ......