public static DataTable Select() { SqlQuery q = new SqlQuery(); q.CommandText = string.Format(@" select 1"); q.CommandType = CommandType.Text; return SqlDataAccess.ExecuteDataset(q, connupCollect).Tables[0]; }
/// <summary> /// SyncParameter /// </summary> private void SyncParameter(SqlCommand cmd, SqlQuery q) { //int parameterCount = q.Parameters.Count; //if (parameterCount > 0) //{ // for (int i = 0; i < parameterCount; i++) // { // q.Parameters[i].SyncParameter(); // } //} }
/// <summary> /// ����Sql���� /// </summary> /// <param name="cmd"></param> /// <param name="q"></param> private void PrepareCommand(SqlCommand cmd, SqlQuery q) { cmd.CommandType = q.CommandType; cmd.CommandText = q.CommandText; cmd.Connection = m_Connection; cmd.CommandTimeout = q.CommandTimeout; cmd.Transaction = m_Trans; if (q.Parameters.Count > 0) { int parameterNum = q.Parameters.Count; for (int i = 0; i < parameterNum; i++) { cmd.Parameters.Add(q.Parameters[i]); } } }
/// <summary> /// ִ���������XmlReader /// </summary> public XmlReader ExecuteXmlReader(SqlQuery q) { SqlCommand cmd = new SqlCommand(); PrepareCommand(cmd, q); XmlReader xmlReader = cmd.ExecuteXmlReader(); SyncParameter(cmd, q); cmd.Parameters.Clear(); return xmlReader; }
/// <summary> ///ִ���������Xml���� /// </summary> public XmlDocument ExecuteXmlDoc(SqlQuery q) { throw new NotImplementedException(); }
/// <summary> /// ִ���������������������(Object) /// </summary> public Object ExecuteScalar(SqlQuery q) { SqlCommand cmd = new SqlCommand(); PrepareCommand(cmd, q); Object oValue = cmd.ExecuteScalar(); SyncParameter(cmd, q); cmd.Parameters.Clear(); return oValue; }
/// <summary> /// ִ���������DataReader /// </summary> public IDataReader ExecuteReader(SqlQuery q) { SqlCommand cmd = new SqlCommand(); PrepareCommand(cmd, q); IDataReader reader = cmd.ExecuteReader(); SyncParameter(cmd, q); cmd.Parameters.Clear(); return reader; }
/// <summary> /// ִ���������Ӱ������ /// </summary> public int ExecuteNonQuery(SqlQuery q) { SqlCommand cmd = new SqlCommand(); PrepareCommand(cmd, q); int affectRows = cmd.ExecuteNonQuery(); SyncParameter(cmd, q); cmd.Parameters.Clear(); return affectRows; }
/// <summary> /// ִ���������DataSet /// Execute query and return DataSet. /// </summary> public DataSet ExecuteDataset(SqlQuery q) { DataSet ds = new DataSet(); SqlCommand cmd = new SqlCommand(); PrepareCommand(cmd, q); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); SyncParameter(cmd, q); cmd.Parameters.Clear(); return ds; }
/// <summary> /// ִ���������XmlReader /// </summary> /// <param name="q">SqlQuery����</param> /// <param name="dp">Sql��������</param> /// <returns>XmlReader</returns> public static XmlReader ExecuteXmlReader(SqlQuery q, DatabaseProperty dp) { SqlDataAccess da = new SqlDataAccess(dp.ConnectionString); da.Open(); return da.ExecuteXmlReader(q); }
/// <summary> /// ִ���������Xml�ĵ� /// </summary> /// <param name="q">SqlQuery����</param> /// <param name="dp">Sql��������</param> /// <returns>Xml�ĵ�</returns> public static XmlDocument ExecuteXmlDoc(SqlQuery q, DatabaseProperty dp) { SqlDataAccess da = new SqlDataAccess(dp.ConnectionString); da.Open(); XmlDocument doc = da.ExecuteXmlDoc(q); da.Close(); return doc; }
/// <summary> /// ִ����������������е�Object /// </summary> /// <param name="q">SqlQuery����</param> /// <param name="dp">Sql��������</param> /// <returns>�������е�Object</returns> public static Object ExecuteScalar(SqlQuery q, DatabaseProperty dp) { SqlDataAccess da = new SqlDataAccess(dp.ConnectionString); da.Open(); object scalar = da.ExecuteScalar(q); da.Close(); return scalar; }
/// <summary> /// ִ���������Ӱ������ /// </summary> /// <param name="q">SqlQuery����</param> /// <param name="dp">Sql��������</param> /// <returns>Ӱ������</returns> public static int ExecuteNonQuery(SqlQuery q, DatabaseProperty dp) { SqlDataAccess da = new SqlDataAccess(dp.ConnectionString); da.Open(); int affectRows = da.ExecuteNonQuery(q); da.Close(); return affectRows; }
/// <summary> /// ִ���������Dataset /// </summary> /// <param name="q">SqlQuery����</param> /// <param name="dp">Sql��������</param> /// <returns>Dataset</returns> public static DataSet ExecuteDataset(SqlQuery q, DatabaseProperty dp) { SqlDataAccess da = new SqlDataAccess(dp.ConnectionString); da.Open(); DataSet ds = da.ExecuteDataset(q); da.Close(); return ds; }
/// <summary> /// �õ���¼������ͳ�� /// </summary> /// <returns>RecordCount</returns> private int GetRecordCount() { int posFrom = this.m_CommandText.IndexOf(" FROM "); int posOrder = this.m_CommandText.IndexOf(" ORDER "); SqlQuery q = new SqlQuery(); if (posOrder > 0) q.CommandText = "SELECT COUNT(1) " + this.m_CommandText.Substring(posFrom, posOrder - posFrom).Trim(); else q.CommandText = "SELECT COUNT(1) " + this.m_CommandText.Substring(posFrom); q.Parameters = this.m_Parameters; Object recordCount = m_DataAccess.ExecuteScalar(q); return (int)recordCount; }