示例#1
0
        public DataTable ExecuteRead(string s)
        {
            CDBInfo       dbinfo = new CDBInfo();
            SqlConnection cnn    = new SqlConnection();

            cnn.ConnectionString = dbinfo.ConnectString();
            //SqlCommand cmd = new SqlCommand();
            //cmd.Connection = cnn;
            //cmd.CommandText = s;
            DataTable dt = new DataTable();

            DataSet ds = new DataSet();

            try
            {
                SqlDataAdapter sda = new SqlDataAdapter(s, cnn);
                sda.Fill(ds);
                dt = ds.Tables[0];
            }
            catch
            {
                ds = null;
            }
            return(dt);
        }
示例#2
0
        public bool MultiExecuteNoneReturn(string[] sqls)
        {
            CDBInfo       dbinfo = new CDBInfo();
            SqlConnection cnn    = new SqlConnection();

            cnn.ConnectionString = dbinfo.ConnectString();
            cnn.Open();
            SqlTransaction st  = cnn.BeginTransaction();
            SqlCommand     cmd = new SqlCommand();

            cmd.Connection  = cnn;
            cmd.Transaction = st;
            try
            {
                foreach (string item in sqls)
                {
                    cmd.CommandText = item;
                    cmd.ExecuteNonQuery();
                }
                st.Commit();
            }
            catch
            {
                st.Rollback();
                return(false);
            }
            return(true);
        }
示例#3
0
        public int ExecuteNoneReturn(string s)
        {
            CDBInfo       dbinfo = new CDBInfo();
            SqlConnection cnn    = new SqlConnection();

            cnn.ConnectionString = dbinfo.ConnectString();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cnn;
            cmd.CommandText = s;

            try
            {
                cnn.Open();
                int i = cmd.ExecuteNonQuery();
                return(i);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.ToString() + "\r" + s);
                return(-1);
            }
        }