c# 查詢sql 返回多個參數

來源:互聯網
上載者:User

標籤:static   多個   查詢   convert   nbsp   pop   rom   編寫   mysql   

1.依據須要查詢mysql 語句,返回三個須要的參數,不是資料集

2.編寫函數例如以下:

    public static void GetParas(string 條件1, out string 傳回值1, out string 傳回值2, out string 傳回值3)
        {
            傳回值1= string.Empty;
            傳回值2= string.Empty;
            傳回值3= string.Empty;


          
            string strSQL = string.Format("Select * from 表 where 欄位1= ‘{0}‘ limit 1", 條件1);

     //運行sql語句

            DataTable dt = ds.Tables[0];
            if (dt != null && dt.Rows.Count == 1)
            {
                object obj = dt.Rows[0][傳回值1"];
                if (obj != null && !(obj is DBNull))
                {
                    傳回值1= Convert.ToString(obj).Replace(" ", "");
                }
                obj = dt.Rows[0]["傳回值2"];
                if (obj != null && !(obj is DBNull))
                {
                    傳回值2= Convert.ToString(obj);
                }
                obj = dt.Rows[0]["傳回值3"];
                if (obj != null && !(obj is DBNull))
                {
                    傳回值3= Convert.ToString(obj);
                }
            }
        }



3.通過上述sql運行,就查詢相應的三個傳回值。

4.調用函數例如以下

 string 傳回值1= string.Empty;
 string 傳回值2= string.Empty;
 string 傳回值3= string.Empty;

 GetParas(查詢條件1, out 傳回值1, out 傳回值2,, out 傳回值3);

c# 查詢sql 返回多個參數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.