鍍金池/ 問答/C#  數(shù)據(jù)庫/ 在asp.net core 中我自定義的一個讀取數(shù)據(jù)庫的類,方法不報錯 但

在asp.net core 中我自定義的一個讀取數(shù)據(jù)庫的類,方法不報錯 但是讀不出數(shù)據(jù)來,表中也有數(shù)據(jù)

public static DataTable LoadDataTable(string connectingStr, string sqlCommand)

    {
        SqlConnection scon = new SqlConnection(connectingStr);

        //SqlConnection scon = cls_ClassLib.scon;

        SqlDataAdapter sread = new SqlDataAdapter();
        sread.SelectCommand = new SqlCommand(
            sqlCommand,
            scon
            );

        sread.SelectCommand.CommandTimeout = 120;

        try
        {
            scon.Open();
        }
        catch (System.Exception ex)
        {

if (DEBUG)

            string tttt = ex.Message + sqlCommand.ToString();

else

            return null;

endif

        }

        DataTable ds = new DataTable();
        try
        {
            sread.Fill(ds);
        }
        catch (System.Exception ex)
        {
            try
            {
                //寫日志
                LogHelper.writeLog((Directory.GetCurrentDirectory() + "/log/" + DateTime.Now.ToString("MMdd") + "_MSSql.txt"),
                     DateTime.Now.ToString("HH:mm:ss") + "\t\t" + ex.Message + "\t\t" + connectingStr + "\t\t" + sqlCommand);
            }
            catch
            {
            }

if (DEBUG)

            string tttt = ex.Message + sqlCommand.ToString();

else

            return null;

endif

        }
        finally
        {
            try
            {
                sread.Dispose();
                scon.Close();
            }
            catch
            {
            }
        }

        return ds;
    }
回答
編輯回答
故人嘆

已解決datatable中已經(jīng)加載了數(shù)據(jù)

2017年2月2日 21:34