EDITORIAL:
The package SQLserver C #: https://www.cnblogs.com/mexihq/p/11636785.html
C # Oracle's Package: https://www.cnblogs.com/mexihq/p/11700741.html
The MySQL C # Package: https://www.cnblogs.com/mexihq/p/12463423.html
The Package Access C #: https://www.cnblogs.com/mexihq/p/12466970.html
In their daily work, usually a large number of items are all the basic operations with the database, so small series of several common database operations packaged into a dll developed to facilitate subsequent use. This article is mainly recorded a gain of C # of Access, delete, change, check the basic operation, and also if there is any problem please enlighten big brother. Follow-up will also have several other common database accordingly finishing. Man of few words said, directly start code code.
Access additions and deletions:
/// <summary>
/// Access insert,delete,update
/// </summary>
/// <param name="sql">insert,delete,update statement</param>
/// <param name="link">link statement</param>
/// <returns>Success:success + Number of affected rows; Fail:reason</returns>
public string Access_Mdb_Insdelupd(string sql, string link)
{
try
{
using (OleDbConnection oleDbConnection = new OleDbConnection(link))
{
DataSet dataSet = new DataSet();
oleDbConnection.Open();
OleDbCommand oleDbCommand = new OleDbCommand(sql, oleDbConnection);
int num = oleDbCommand.ExecuteNonQuery();
oleDbConnection.Close();
return "success" + num;
}
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
Access the investigation:
/// <summary>
/// Access select
/// </summary>
/// <param name="sql">select statement</param>
/// <param name="link">link statement</param>
/// <param name="record">Success:success; Fail:reason</param>
/// <returns>select result</returns>
public DataSet Access_Mdb_Select(string sql, string link, out string record)
{
try
{
DataSet dataSet = new DataSet();
using (OleDbConnection oleDbConnection = new OleDbConnection(link))
{
oleDbConnection.Open();
OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(sql, oleDbConnection);
oleDbDataAdapter.Fill(dataSet, "sample");
oleDbDataAdapter.Dispose();
oleDbConnection.Close();
record = "success";
return dataSet;
}
}
catch (Exception ex)
{
DataSet dataSet = new DataSet();
record = ex.Message.ToString();
return dataSet;
}
}