}
//返回DataSet
public DataSet DataSetQuery(string Sql,string TableName,int StarIndex,int Count)
{
DataConnection=DataConn();
DataConnection.Open();
DataAdapter=new SqlDataAdapter(Sql,DataConnection);
DataSet=new DataSet();
DataAdapter.Fill(DataSet,StarIndex,Count,TableName);
DataConnection.Close();
DataConnection.Dispose();
return DataSet;
}
public void DataDo(string sqlstr)
{
DataConnection=DataConn();
SqlCommand mycom=DataConnection.CreateCommand();
mycom.CommandText=sqlstr;
DataConnection.Open();
mycom.ExecuteNonQuery();
DataConnection.Close();
}
//返回DataSet 开始行到结束行
public bool EditData(string Sql)
{
DataConnection=DataConn();
DataConnection.Open();
DataCommand=new SqlCommand(Sql,DataConnection);
try
{
DataCommand.ExecuteNonQuery();
DataConnection.Close();
return true;
}
catch(Exception ex)
{
System.Console.Write(ex.Message.ToString());
DataConnection.Close();
return false;
}
}
//执行成功返回真,否则返回假.
public object ExecuteScalar(string Sql)
{
DataConnection=DataConn();
DataConnection.Open();
DataCommand=new SqlCommand(Sql,DataConnection);
try
{
object back = DataCommand.ExecuteScalar();
DataConnection.Close();
return back;
}
catch(Exception ex)
{
System.Console.Write(ex.Message.ToString());
DataConnection.Close();
return null;
}
}
//返回一个值的查询语句
public DataSet EditData(DataSet DataSet,SqlDataAdapter myda,string TableName)
{
DataComBuilder=new SqlCommandBuilder(myda);
myda.UpdateCommand=DataComBuilder.GetUpdateCommand();
myda.DeleteCommand=DataComBuilder.GetDeleteCommand();
myda.InsertCommand=DataComBuilder.GetInsertCommand();
myda.Update(DataSet,TableName);
DataSet.AcceptChanges();
this.CloseConnection();
return DataSet;
}
//修改DataSet 并且修改数据库值存储过程
public bool DataProcedure(string ProcedureName)
{
DataConnection=DataConn();
DataConnection.Open();
DataCommand=new SqlCommand();
DataCommand.CommandText=ProcedureName;
DataCommand.Connection=DataConnection;
DataCommand.CommandType=System.Data.CommandType.StoredProcedure;
try
{
DataCommand.ExecuteNonQuery();
return true;
}
catch(Exception ex)
{
System.Console.Write(ex.Message.ToString());
return false;
}
}
//无参数存储过程的执行 返回执行真假
public void CloseConnection()
{
if(DataReader!=null)
{
DataReader.Close();
DataReader=null;
}
DataConnection.Close();
DataConnection.Dispose();
}
//关闭连接
}
}
……