using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;namespace StudentMangerSystem
{
class DBConn
{
//==============建立连接=================================
public static OleDbConnection DBCon()
{ String connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|xb.mdb";
return new OleDbConnection(connectionString);
}
public static DialogResult MessageOk(string value)
{
return MessageBox.Show(value, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public static DataTable ExecSqlReturnDataTable(string SqlStr)
{
DataSet ds = new DataSet();
DataTable table = new DataTable();
OleDbConnection con = DBCon();
try
{
OleDbDataAdapter da = new OleDbDataAdapter(SqlStr, con);
da.Fill(ds, "Table");
table = ds.Tables["Table"];
return table;
}
catch (Exception ex)
{
con.Close();
DBConn.MessageOk(ex.Message);
return table;
}
finally
{
con.Close();
}
}
/// <summary>
public static bool ExecSqlReturn(string SqlStr, string ParaPic, byte[] Pic)
{
OleDbConnection con = DBCon();
OleDbCommand com = new OleDbCommand();
com.Parameters.Add(ParaPic, OleDbType.Date);
com.Parameters[0].Value = Pic;
com.Connection = con;
com.CommandText = SqlStr;
try
{
com.ExecuteNonQuery();
con.Close(); return true;
}
catch (Exception ex)
{
DBConn.MessageOk(ex.Message);
return false;
}
finally
{
con.Close();
}
}
/// <summary>
public static bool ExecSqlReturn(string SqlStr)
{ OleDbConnection con = DBCon();
OleDbCommand com = new OleDbCommand();
com.Connection = con;
com.CommandText = SqlStr;
try
{
com.ExecuteNonQuery();
con.Close(); return true;
}
catch (Exception ex)
{
DBConn.MessageOk(ex.Message);
return false;
}
finally
{
con.Close();
}
}
/// <summary>
/// 返回单一值的查询
/// </summary>
public static object ExecSqlScalar(string SqlStr)
{
OleDbConnection con = DBCon();
OleDbCommand com = new OleDbCommand();
com.Connection = con;
com.CommandText = SqlStr;
try
{
return com.ExecuteScalar();
}
catch
{
con.Close();
return null;
}
finally
{
con.Close();
}
}
}
}
紧急啊~~
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;namespace StudentMangerSystem
{
class DBConn
{
//==============建立连接=================================
public static OleDbConnection DBCon()
{ String connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|xb.mdb";
return new OleDbConnection(connectionString);
}
public static DialogResult MessageOk(string value)
{
return MessageBox.Show(value, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public static DataTable ExecSqlReturnDataTable(string SqlStr)
{
DataSet ds = new DataSet();
DataTable table = new DataTable();
OleDbConnection con = DBCon();
try
{
OleDbDataAdapter da = new OleDbDataAdapter(SqlStr, con);
da.Fill(ds, "Table");
table = ds.Tables["Table"];
return table;
}
catch (Exception ex)
{
con.Close();
DBConn.MessageOk(ex.Message);
return table;
}
finally
{
con.Close();
}
}
/// <summary>
public static bool ExecSqlReturn(string SqlStr, string ParaPic, byte[] Pic)
{
OleDbConnection con = DBCon();
OleDbCommand com = new OleDbCommand();
com.Parameters.Add(ParaPic, OleDbType.Date);
com.Parameters[0].Value = Pic;
com.Connection = con;
com.CommandText = SqlStr;
try
{
com.ExecuteNonQuery();
con.Close(); return true;
}
catch (Exception ex)
{
DBConn.MessageOk(ex.Message);
return false;
}
finally
{
con.Close();
}
}
/// <summary>
public static bool ExecSqlReturn(string SqlStr)
{ OleDbConnection con = DBCon();
OleDbCommand com = new OleDbCommand();
com.Connection = con;
com.CommandText = SqlStr;
try
{
com.ExecuteNonQuery();
con.Close(); return true;
}
catch (Exception ex)
{
DBConn.MessageOk(ex.Message);
return false;
}
finally
{
con.Close();
}
}
/// <summary>
/// 返回单一值的查询
/// </summary>
public static object ExecSqlScalar(string SqlStr)
{
OleDbConnection con = DBCon();
OleDbCommand com = new OleDbCommand();
com.Connection = con;
com.CommandText = SqlStr;
try
{
return com.ExecuteScalar();
}
catch
{
con.Close();
return null;
}
finally
{
con.Close();
}
}
}
}
紧急啊~~
解决方案 »
- 为什么不能及时更新?请各位高手帮我一下。
- 3D碰撞检测里“碰撞”是什么意思
- MicrosoftReportview微软报表问题,急!!
- Do me a favor...
- 用C#写代理程序,将本机所有网络访问默认连接到代理服务器?!
- 点击CheckBox 按钮牛后进不了 ItemCommand事件里设置的断点里
- streamreader流,如何判断读到文件末尾?
- 请教OLE DB和ODBC这两种连接方式的区别(.net 2.0)
- C#如何获取ati显卡目前的工作频率
- 输入字符串格式不正确,来看看吧,亲!!!!
- 请问imageList.TransparentColor属性
- C#中关于字符串合并的问题
public static OleDbConnection DBCon()
{ String connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|xb.mdb";
OleDbConnection con = new OleDbConnection(connectionString);
con.Open();
return con;
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;namespace StudentMangerSystem
{
class DBConn
{
//==============建立连接=================================
public static OleDbConnection DBCon()
{ String connectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|xb.mdb";
OleDbConnection con = new OleDbConnection(connectionString);
if (con .State != ConnectionState.Open)
{
con.Open(); //打开连接
}
return con;
}
public static DialogResult MessageOk(string value)
{
return MessageBox.Show(value, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
public static DataTable ExecSqlReturnDataTable(string SqlStr)
{
DataSet ds = new DataSet();
DataTable table = new DataTable();
OleDbConnection con = DBCon();
try
{
OleDbDataAdapter da = new OleDbDataAdapter(SqlStr, con);
da.Fill(ds, "Table");
table = ds.Tables["Table"];
return table;
}
catch (Exception ex)
{
con.Close();
DBConn.MessageOk(ex.Message);
return table;
}
finally
{
con.Close();
}
}
/// <summary>
public static bool ExecSqlReturn(string SqlStr, string ParaPic, byte[] Pic)
{
OleDbConnection con = DBCon();
OleDbCommand com = new OleDbCommand();
com.Parameters.Add(ParaPic, OleDbType.Date);
com.Parameters[0].Value = Pic;
com.Connection = con;
com.CommandText = SqlStr;
try
{
com.ExecuteNonQuery();
con.Close(); return true;
}
catch (Exception ex)
{
DBConn.MessageOk(ex.Message);
return false;
}
finally
{
con.Close();
}
}
/// <summary>
public static bool ExecSqlReturn(string SqlStr)
{ OleDbConnection con = DBCon();
OleDbCommand com = new OleDbCommand();
com.Connection = con;
com.CommandText = SqlStr;
try
{
com.ExecuteNonQuery();
con.Close(); return true;
}
catch (Exception ex)
{
DBConn.MessageOk(ex.Message);
return false;
}
finally
{
con.Close();
}
}
/// <summary>
/// 返回单一值的查询
/// </summary>
public static object ExecSqlScalar(string SqlStr)
{
OleDbConnection con = DBCon();
OleDbCommand com = new OleDbCommand();
com.Connection = con;
com.CommandText = SqlStr;
try
{
return com.ExecuteScalar();
}
catch
{
con.Close();
return null;
}
finally
{
con.Close();
}
}
}
}