展开全部
自己程序中定义了一个数据库操作的类,用的是Server2000的数据库,仅供参考:
namespace
ComtactManager
{
class
DataBase:IDisposable
{
private
SqlConnection
Sqlconn;
public
static
string
sConn
=
"server=localhost;database=HqCompact;uid=sa;pwd=";
public
void
Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
protected
void
Dispose(bool
disposing)
{
if
(disposing)
return;
if
(Sqlconn
!=
null)
{
Sqlconn.Dispose();
Sqlconn
=
null;
}
}
public
void
Open()
{
if
(Sqlconn
==
null)
{
Sqlconn
=
new
SqlConnection(sConn);
Sqlconn.Open();
}
}
public
void
Close()
{
if
(Sqlconn
!=
null)
Sqlconn.Close();
}
public
DataSet
RunSelectSQL(string
sSQLString)
{
this.Open();
DataSet
SqlDS
=
new
DataSet();
SqlDataAdapter
SqlDA
=
new
SqlDataAdapter(sSQLString,this.Sqlconn);
SqlDA.Fill(SqlDS);
return
SqlDS;
}
public
bool
RunReaderSQL(string
sSQLString)
{
this.Open();
SqlCommand
cmd
=
new
SqlCommand(sSQLString,
this.Sqlconn);
SqlDataReader
reader
=
cmd.ExecuteReader();
if
(reader.Read())
{
reader.Close();
return
true;
}
else
{
reader.Close();
return
false;
}
}
public
SqlDataReader
getReader(string
strSelect)
{
SqlCommand
cmd
=
new
SqlCommand(strSelect,Sqlconn);
SqlDataReader
reader
=
cmd.ExecuteReader();
return
reader;
}
public
void
RunDelOrInsSQL(string
sSQLString)
{
this.Open();
SqlCommand
Sqlcomm
=
new
SqlCommand(sSQLString,
this.Sqlconn);
Sqlcomm.ExecuteNonQuery();
}
public
void
RunProcedure(SqlCommand
cmd)
{
cmd.ExecuteNonQuery();
}
}
}
namespace
ComtactManager
{
class
DataBase:IDisposable
{
private
SqlConnection
Sqlconn;
public
static
string
sConn
=
"server=localhost;database=HqCompact;uid=sa;pwd=";
public
void
Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
protected
void
Dispose(bool
disposing)
{
if
(disposing)
return;
if
(Sqlconn
!=
null)
{
Sqlconn.Dispose();
Sqlconn
=
null;
}
}
public
void
Open()
{
if
(Sqlconn
==
null)
{
Sqlconn
=
new
SqlConnection(sConn);
Sqlconn.Open();
}
}
public
void
Close()
{
if
(Sqlconn
!=
null)
Sqlconn.Close();
}
public
DataSet
RunSelectSQL(string
sSQLString)
{
this.Open();
DataSet
SqlDS
=
new
DataSet();
SqlDataAdapter
SqlDA
=
new
SqlDataAdapter(sSQLString,this.Sqlconn);
SqlDA.Fill(SqlDS);
return
SqlDS;
}
public
bool
RunReaderSQL(string
sSQLString)
{
this.Open();
SqlCommand
cmd
=
new
SqlCommand(sSQLString,
this.Sqlconn);
SqlDataReader
reader
=
cmd.ExecuteReader();
if
(reader.Read())
{
reader.Close();
return
true;
}
else
{
reader.Close();
return
false;
}
}
public
SqlDataReader
getReader(string
strSelect)
{
SqlCommand
cmd
=
new
SqlCommand(strSelect,Sqlconn);
SqlDataReader
reader
=
cmd.ExecuteReader();
return
reader;
}
public
void
RunDelOrInsSQL(string
sSQLString)
{
this.Open();
SqlCommand
Sqlcomm
=
new
SqlCommand(sSQLString,
this.Sqlconn);
Sqlcomm.ExecuteNonQuery();
}
public
void
RunProcedure(SqlCommand
cmd)
{
cmd.ExecuteNonQuery();
}
}
}
展开全部
自己程序中定义了一个数据库操作的类,用的是Server2000的数据库,仅供参考:
namespace ComtactManager
{
class DataBase:IDisposable
{
private SqlConnection Sqlconn;
public static string sConn = "server=localhost;database=HqCompact;uid=sa;pwd=";
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
protected void Dispose(bool disposing)
{
if (disposing)
return;
if (Sqlconn != null)
{
Sqlconn.Dispose();
Sqlconn = null;
}
}
public void Open()
{
if (Sqlconn == null)
{
Sqlconn = new SqlConnection(sConn);
Sqlconn.Open();
}
}
public void Close()
{
if (Sqlconn != null)
Sqlconn.Close();
}
public DataSet RunSelectSQL(string sSQLString)
{
this.Open();
DataSet SqlDS = new DataSet();
SqlDataAdapter SqlDA = new SqlDataAdapter(sSQLString,this.Sqlconn);
SqlDA.Fill(SqlDS);
return SqlDS;
}
public bool RunReaderSQL(string sSQLString)
{
this.Open();
SqlCommand cmd = new SqlCommand(sSQLString, this.Sqlconn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
reader.Close();
return true;
}
else
{
reader.Close();
return false;
}
}
public SqlDataReader getReader(string strSelect)
{
SqlCommand cmd = new SqlCommand(strSelect,Sqlconn);
SqlDataReader reader = cmd.ExecuteReader();
return reader;
}
public void RunDelOrInsSQL(string sSQLString)
{
this.Open();
SqlCommand Sqlcomm = new SqlCommand(sSQLString, this.Sqlconn);
Sqlcomm.ExecuteNonQuery();
}
public void RunProcedure(SqlCommand cmd)
{
cmd.ExecuteNonQuery();
}
}
}
namespace ComtactManager
{
class DataBase:IDisposable
{
private SqlConnection Sqlconn;
public static string sConn = "server=localhost;database=HqCompact;uid=sa;pwd=";
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true);
}
protected void Dispose(bool disposing)
{
if (disposing)
return;
if (Sqlconn != null)
{
Sqlconn.Dispose();
Sqlconn = null;
}
}
public void Open()
{
if (Sqlconn == null)
{
Sqlconn = new SqlConnection(sConn);
Sqlconn.Open();
}
}
public void Close()
{
if (Sqlconn != null)
Sqlconn.Close();
}
public DataSet RunSelectSQL(string sSQLString)
{
this.Open();
DataSet SqlDS = new DataSet();
SqlDataAdapter SqlDA = new SqlDataAdapter(sSQLString,this.Sqlconn);
SqlDA.Fill(SqlDS);
return SqlDS;
}
public bool RunReaderSQL(string sSQLString)
{
this.Open();
SqlCommand cmd = new SqlCommand(sSQLString, this.Sqlconn);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
reader.Close();
return true;
}
else
{
reader.Close();
return false;
}
}
public SqlDataReader getReader(string strSelect)
{
SqlCommand cmd = new SqlCommand(strSelect,Sqlconn);
SqlDataReader reader = cmd.ExecuteReader();
return reader;
}
public void RunDelOrInsSQL(string sSQLString)
{
this.Open();
SqlCommand Sqlcomm = new SqlCommand(sSQLString, this.Sqlconn);
Sqlcomm.ExecuteNonQuery();
}
public void RunProcedure(SqlCommand cmd)
{
cmd.ExecuteNonQuery();
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ADO.NET
具体的.NET 内置了三种类型的数据库对象
OLEDB,SQL,ORECAL
具体的.NET 内置了三种类型的数据库对象
OLEDB,SQL,ORECAL
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询