c# 查询sql 返回多个参数

来源:互联网 发布:mac windows7 iso下载 编辑:程序博客网 时间:2024/05/16 17:58

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);

0 0