在asp.net core 中我自定义的一个读取数据库的类,方法不报错 但是读不出数据来,表中也有数据

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;
    }
阅读 2.3k
1 个回答

已解决datatable中已经加载了数据

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进