Informix 中执行多条SQL(Execute Script)

有的时候我们需要在ADO.NET中同时执行多条的SQL语法,我们要如何处理,

例如下:

        //查詢基本資料
        private static void TestQry()
        {
            DataTable dtReturn =new DataTable();
            //查詢基礎資料
            try
            {
                //模擬查詢原始資料
                string strSql1 = @"
Select id,name from databasename@dblinkname:tablename
union
Select id,name from databasename@dblinkname:tablename
into temp tmp_tablename with no log;
";
                string strSql2 = @"
select * from tmp_tablename;
";
                string strSql3 = @"
drop table tmp_tablename;
";
                using (IfxConnection conn = new IfxConnection(gsConnStr))
                {
                    using (IfxCommand cmd = new IfxCommand(strSql1, conn))
                    {
                        conn.Open();

                        //
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = strSql1;
                        cmd.ExecuteNonQuery();

                        using (IfxDataAdapter ad = new IfxDataAdapter(strSql2, conn))
                        {
                            ad.Fill(dtReturn);
                        }

                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = strSql3;
                        cmd.ExecuteNonQuery();

                        conn.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                dtReturn = null;
                Console.WriteLine(ex.Message);
            }
        }

 

posted on 2016-12-05 11:49  chen110xi  阅读(913)  评论(0编辑  收藏  举报