日期:2014-05-17  浏览次数:20708 次

ADO.NET
用sql语句从数据库查询的数据执行的时候怎么能返回datatable
ADO.NET 数据库 SQL

------解决方案--------------------
refer:
 public DataTable ExecuteQuery(string sql)
        {
            using (SqlConnection sqlConnection = new SqlConnection())
            {
                sqlConnection.ConnectionString = "server=.;database=test;uid=sa;pwd=123456;";
                sqlConnection.Open();

                SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
                SqlDataAdapter sda = new SqlDataAdapter(sqlCommand);
                DataSet ds = new DataSet();
                sda.Fill(ds);
                return ds.Tables[0];
            }
        }

------解决方案--------------------
https://www.google.com.hk/search?q=ado.net+%E5%A2%9E%E5%88%A0%E6%94%B9%E6%9F%A5&oq=ado.net+%E5%A2%9E%E5%88%A0%E6%94%B9%E6%9F%A5&aqs=chrome.0.69i57j69i60j69i61l2j0l2.206j0&sourceid=chrome&ie=UTF-8
------解决方案--------------------
引用:
refer:
 public DataTable ExecuteQuery(string sql)
        {
            using (SqlConnection sqlConnection = new SqlConnection())
            {