示例#1
0
        public static DataTable ExecuteQuery(string query, object[] thamso = null)
        {
            SqlServerHelper.ConnectDataBase();

            SqlCommand cmd = new SqlCommand(query, connection);

            if (thamso != null)
            {
                string[] dsThamSo = query.Split(' ');
                int      i        = 0;
                foreach (string item in dsThamSo)
                {
                    if (item.Contains("@"))
                    {
                        cmd.Parameters.AddWithValue(item, thamso[i]);
                        i++;
                    }
                }
            }
            DataTable      ans      = new DataTable();
            SqlDataAdapter apdapter = new SqlDataAdapter(cmd);

            apdapter.Fill(ans);

            Disconnect();
            return(ans);
        }