MySQL in EF returns to the DataTable public class library

Source: Internet
Author: User
Tags static class

public static class SqlHelper {//<summary>///EF SQL statements return dataTable//</summary> <param name= "db" >ef data context </param>///<param name= "SQL" > statements </param>///&L T;param name= "Parameters" > Parameters </param>//<returns></returns> public static DataTable Sq Lqueryfordatatatable (This Database db, String sql, sqlparameter[] parameters=null) {mysqlconnection con            n = new mysqlconnection (); Conn. ConnectionString = db.            connection.connectionstring; IF (Conn. state! = ConnectionState.Open) {Conn.            Open ();            } mysqlcommand cmd = new Mysqlcommand (); Cmd.            Connection = conn;            Cmd.commandtext = SQL; if (parameters!=null && parameters. Length > 0) {foreach (var item in parameters) {cmd.    Parameters.Add (item);            }} Mysqldataadapter adapter = new Mysqldataadapter (cmd);            DataTable table = new DataTable (); Adapter.            Fill (table);        return table; }    }

  

MySQL in EF returns to the DataTable public class library

Related Article

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.