C # Query SQL returns multiple parameters

Source: Internet
Author: User

1. Query the MySQL statement as needed, return three required parameters, not a dataset

2. Write the function as follows:

public static void Getparas (string condition 1, out string return value 1, out string return value 2, out string return value 3)
{
The return value is 1= string. Empty;
The return value is 2= string. Empty;
The return value is 3= string. Empty;



String strSQL = String. Format ("SELECT * from table where field 1= ' {0} ' limit 1", condition 1);

Execute SQL statement

DataTable dt = ds. Tables[0];
if (dt! = null && dt. Rows.Count = = 1)
{
Object obj = dt. rows[0][return value 1 "];
if (obj! = null &&!) ( obj is DBNull))
{
The return value 1= convert.tostring (obj). Replace ("", "");
}
obj = dt. rows[0]["return value 2"];
if (obj! = null &&!) ( obj is DBNull))
{
The return value 2= convert.tostring (obj);
}
obj = dt. rows[0]["return value 3"];
if (obj! = null &&!) ( obj is DBNull))
{
The return value 3= convert.tostring (obj);
}
}
}



3. With the above SQL execution, the corresponding three return values are queried.

4. Call the function as follows

String returns a value of 1= string. Empty;
String returns a value of 2= string. Empty;
String returns a value of 3= string. Empty;

Getparas (query condition 1, out return value 1, out return value 2, out return value 3);

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

C # Query SQL returns multiple parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.