Need to get empty datatable in .net with database table schema

前端 未结 10 836
闹比i
闹比i 2021-02-07 04:40

What is the best way to create an Empty DataTable object with the schema of a sql server table?

10条回答
  •  清歌不尽
    2021-02-07 05:09

    Here's what I did:

    var conn = new SqlConnection("someConnString");
    var cmd = new SqlCommand("SET FMTONLY ON; SELECT * FROM MyTable; SET FMTONLY OFF;",conn); 
    var dt = new DataTable();
    conn.Open();
    dt.Load(cmd.ExecuteReader());
    conn.Dispose();
    

    Works well. Thanks AdaTheDev.

提交回复
热议问题