将SQL表读入C#DataTable

将SQL表读入C#DataTable,第1张

将SQL表读入C#DataTable

在这里,给它一个镜头(这只是一个伪代码

using System;using System.Data;using System.Data.SqlClient;public class PullDataTest{    // your data table    private DataTable dataTable = new DataTable();    public PullDataTest()    {    }    // your method to pull data from database to datatable       public void PullData()    {        string connString = @"your connection string here";        string query = "select * from table";        SqlConnection conn = new SqlConnection(connString);     SqlCommand cmd = new SqlCommand(query, conn);        conn.Open();        // create data adapter        SqlDataAdapter da = new SqlDataAdapter(cmd);        // this will query your database and return the result to your datatable        da.Fill(dataTable);        conn.Close();        da.Dispose();    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5427609.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存