How to receive a SQL-Statement as a DataTable

前端 未结 4 1063
梦谈多话
梦谈多话 2020-12-22 04:10

I have the following code:

public static DataTable GetDataTable(string sConnStr, string sTable)
{
    DataTable dt = new DataTable();

    SqlConnection sqlC         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-22 04:25

    Don't use a SqlDataReader, use a SqlDataAdapter. A DataReader is for fast, forward-only operations, while the DataAdapter is geared towards set-based operations.

    See MSDN: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx

    See http://www.dotnetperls.com/sqldataadapter for a simple example.

提交回复
热议问题