#region 执行SQL不带返回记录
        public static bool ExecuteNonQuery(string commandText, OleDbConnection connection, CommandType commandType, int nSrcID, OleDbTransaction trans)
        {
            TraceSql(commandText);            bool bNeedClose = false;
            try
            {
                if (connection == null)
                {
                    // Create a connection
                    if (nSrcID < 0) nSrcID = defaltConnect;
                    connection = new OleDbConnection(GetConnectionString(nSrcID));
                }                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                    bNeedClose = true;
                }                // Create a command and prepare it for execution
                OleDbCommand cmd = new OleDbCommand(commandText, connection, trans);
                // Finally, execute the command
                int retval = cmd.ExecuteNonQuery();                // Detach the SqlParameters from the command object, so they can be used again
                if (bNeedClose)
                    connection.Close();                return true;
            }
            catch
            {
                if (bNeedClose)
                    connection.Close();                return false;
            }
        }        public static bool ExecuteNonQuery(string commandText)
        {
            return ExecuteNonQuery(commandText, null, CommandType.Text, defaltConnect, null);
        }        public static bool ExecuteNonQuery(string commandText, int nSrcID)
        {
            return ExecuteNonQuery(commandText, null, CommandType.Text, nSrcID, null);
        }        public static bool ExecuteNonQuery(string commandText, OleDbConnection connection)
        {
            return ExecuteNonQuery(commandText, connection, CommandType.Text, defaltConnect, null);
        }        public static bool ExecuteNonQuery(string commandText, OleDbTransaction trans)
        {
            return ExecuteNonQuery(commandText, trans.Connection, CommandType.Text, defaltConnect, trans);
        }        public static bool ExecuteNonQuery(string commandText, OleDbConnection connection, OleDbTransaction trans)
        {
            return ExecuteNonQuery(commandText, connection, CommandType.Text, defaltConnect, trans);
        }        #endregion        #region 执行SQL带有返回结果(DataSet)        public static DataSet ExecuteDataset(string commandText, OleDbConnection connection, CommandType commandType, int nSrcID, OleDbTransaction trans)
        {
            TraceSql(commandText);            bool bNeedClose = false;
         
            try
            {
                if (connection == null)
                {
                    if (nSrcID < 0) nSrcID = defaltConnect;                    connection = new OleDbConnection(GetConnectionString(nSrcID));
                }                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                    bNeedClose = true;
                }
                // Create a command and prepare it for execution
                OleDbCommand cmd = new OleDbCommand(commandText, connection, trans);                // Create the DataAdapter & DataSet
                using (OleDbDataAdapter da = new OleDbDataAdapter(cmd))
                {
                    DataSet ds = new DataSet();                    // Fill the DataSet using default values for DataTable names, etc
                    da.Fill(ds);                    //close connection for later using.
                    if (bNeedClose)
                        connection.Close();                    // Return the dataset
                    return ds;
                }
            }
            catch (Exception ee)
            {
                if (bNeedClose)
                    connection.Close();
                throw ee;
                //return null;
            }
        }        public static DataSet ExecuteDataset(string commandText)
        {
            return ExecuteDataset(commandText, null, CommandType.Text, defaltConnect, null);
        }        public static DataSet ExecuteDataset(string commandText, OleDbConnection connection)
        {
            return ExecuteDataset(commandText, connection, CommandType.Text, defaltConnect, null);
        }        public static DataSet ExecuteDataset(string commandText, int nSrcID)
        {
            return ExecuteDataset(commandText, null, CommandType.Text, nSrcID, null);
        }        public static DataSet ExecuteDataset(string commandText, OleDbTransaction trans)
        {
            return ExecuteDataset(commandText, trans.Connection, CommandType.Text, defaltConnect, trans);
        }        #endregion        #region 执行SQLReader
        public static OleDbDataReader ExecuteReader(string commandText, OleDbConnection connection, CommandType commandType, int nSrcID, OleDbTransaction trans)
        {
            TraceSql(commandText);
            bool bNeedClose = false;
            try
            {
                //create connection
                if (connection == null)
                {
                    if (nSrcID < 0) nSrcID = defaltConnect;
                    connection = new OleDbConnection(GetConnectionString(nSrcID));
                }                if (connection.State != ConnectionState.Open)
                {
                    connection.Open();
                    bNeedClose = true;
                }                // Create a command and prepare it for execution
                OleDbCommand cmd = new OleDbCommand(commandText, connection);
                cmd.Transaction = trans;
                //return reader 
                OleDbDataReader reader = null;                if (bNeedClose)
                    reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                else
                    reader = cmd.ExecuteReader();                return reader;
            }
            catch (Exception ee)
            {
                if (bNeedClose)
                    connection.Close();                throw ee;
                // return null;
            }
        }        public static OleDbDataReader ExecuteReader(string commandText)
        {
            return ExecuteReader(commandText, null, CommandType.Text, defaltConnect, null);
        }        public static OleDbDataReader ExecuteReader(string commandText, OleDbConnection connection)
        {
            return ExecuteReader(commandText, connection, CommandType.Text, defaltConnect, null);
        }        public static OleDbDataReader ExecuteReader(string commandText, int nSrcID)
        {
            return ExecuteReader(commandText, null, CommandType.Text, nSrcID, null);
        }        public static OleDbDataReader ExecuteReader(string commandText, OleDbTransaction trans)
        {
            return ExecuteReader(commandText, trans == null ? null : trans.Connection, CommandType.Text, defaltConnect, trans);
        }
        #endregion

解决方案 »

  1.   

    #region 执行存储过程
            public static bool ExeStoredProcedure(string procedureName, OleDbConnection connection, int nSrcID, ArrayList arrInParaType, ArrayList arrInParaValue, ArrayList arrOutParaType, ArrayList arrOutParaValue, OleDbTransaction trans)
            {
                bool okExecute = false;
                bool bNeedClose = false;
                try
                {
                    //create connection
                    if (connection == null)
                    {
                        if (nSrcID < 0) nSrcID = defaltConnect;
                        connection = new OleDbConnection(GetConnectionString(nSrcID));
                    }                if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                        bNeedClose = true;
                    }                // Create a command and prepare it for execution
                    OleDbCommand cmd = new OleDbCommand(procedureName, connection);
                    if (trans != null)
                        cmd.Transaction = trans;                cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Clear();                if (arrInParaType != null)
                    {
                        for (int i = 0; i < arrInParaType.Count; i++)
                        {
                            OleDbParameter p = new OleDbParameter();
                            p.OleDbType = (OleDbType)arrInParaType[i];
                            p.Value = arrInParaValue[i];
                            p.Direction = ParameterDirection.Input;
                            cmd.Parameters.Add(p);
                        }
                    }                if (arrOutParaType != null)
                    {
                        for (int i = 0; i < arrOutParaType.Count; i++)
                        {
                            OleDbParameter p = new OleDbParameter();
                            p.OleDbType = (OleDbType)arrOutParaType[i];
                            p.Direction = ParameterDirection.Output;
                            if (p.OleDbType == OleDbType.VarChar)
                                p.Size = 1000;
                            else
                                p.Size = 30;                        cmd.Parameters.Add(p);
                        }
                    }                cmd.ExecuteNonQuery();                if (arrInParaType != null)
                    {
                        arrOutParaValue.Clear();
                        for (int i = arrInParaType.Count; i < arrOutParaType.Count + arrInParaType.Count; i++)
                        {
                            OleDbType outType = (OleDbType)arrOutParaType[i - arrInParaType.Count];
                            object outValue = cmd.Parameters[i].Value;
                            if (outType == OleDbType.VarChar)
                            {
                                string outString = outValue.ToString();
                                if (outString != null)
                                    arrOutParaValue.Add(outString.Trim('\0'));
                                else
                                    arrOutParaValue.Add(outString);
                            }
                            else
                            {
                                arrOutParaValue.Add(outValue);
                            }
                        }
                    }                if (bNeedClose)
                        connection.Close();                okExecute = true;
                }
                catch
                {
                    if (bNeedClose)
                    {
                        connection.Close();
                    }
                    okExecute = false;
                }            TraceSql(procedureName, arrInParaType, arrInParaValue, arrOutParaType, arrOutParaValue);
                return okExecute;
            }        public static bool ExeStoredProcedure(string procedurename, ArrayList arrInParaType, ArrayList arrInParaValue, ArrayList arrOutParaType, ArrayList arrOutParaValue)
            {
                return ExeStoredProcedure(procedurename, null, defaltConnect, arrInParaType, arrInParaValue, arrOutParaType, arrOutParaValue, null);
            }        public static bool ExeStoredProcedure(string procedurename, ArrayList arrInParaType, ArrayList arrInParaValue, ArrayList arrOutParaType, ArrayList arrOutParaValue, OleDbTransaction trans)
            {
                return ExeStoredProcedure(procedurename, null, defaltConnect, arrInParaType, arrInParaValue, arrOutParaType, arrOutParaValue, trans);
            }        public static bool ExeStoredProcedure(string procedurename, OleDbConnection connection, ArrayList arrInParaType, ArrayList arrInParaValue, ArrayList arrOutParaType, ArrayList arrOutParaValue)
            {
                return ExeStoredProcedure(procedurename, connection, defaltConnect, arrInParaType, arrInParaValue, arrOutParaType, arrOutParaValue, null);
            }        public static bool ExeStoredProcedure(string procedurename, int nSrcID, ArrayList arrInParaType, ArrayList arrInParaValue, ArrayList arrOutParaType, ArrayList arrOutParaValue)
            {
                return ExeStoredProcedure(procedurename, null, nSrcID, arrInParaType, arrInParaValue, arrOutParaType, arrOutParaValue, null);
            }
    各位大哥 这是别人封状好的操作数据库的类库  我要在display 的 页面上的饿label里面显示数据库中的一条记录或着整个表的内容 怎么写  详细代码!!!!!!!!!!!!!!!
      

  2.   

    DataBindings.Add(string propertyname,object DataSourceUpdateMode,string datamember);
      

  3.   

    我不要绑定啊,就是把他显示在label里面啊\
      

  4.   

    我看那个东西可以返回一个datatable对象呀.
    你可以在datatable中将数据读出来放到lable上就可以了