有的时候我们需要在ADO.NET中同时执行多条的SQL语法,我们要如何处理,
例如下:
//查詢基本資料 private static void TestQry() { DataTable dtReturn =new DataTable(); //查詢基礎資料 try { //模擬查詢原始資料 string strSql1 = @" Select id,name from [email protected]:tablename union Select id,name from [email protected]: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); } }
时间: 2024-10-28 01:05:55