Report Viewer X Dapper

前端 未结 4 1772
野的像风
野的像风 2021-01-18 16:11

I\'m feeding a ReportDataSource with a query using Dapper. However, I have an empty report, even with an IEnumerable loaded data. When you spend a

4条回答
  •  醉梦人生
    2021-01-18 16:35

    To Get the DataTable from SqliteDB using Dapper.

    1. Pass the query such as "select*from table" inside the method.

    2. list is formed, by executing query.

    3. Then serialize the object into Json and then deserialize the Json into the DataTable.

      public DataTable method(string query)
         {
             string connection = @"Data Source= C:\User\DBFolder\sampleDB.db;Version=3;New=False;Compress=True;";
      
             using (IDbConnection dbConnection = new SQLiteConnection(connection))
              {
                  dbConnection.Open();
                  var output1 = dbConnection.Query(query).ToList();
                  dbConnection.Close();
                  var json = JsonConvert.SerializeObject(output1);
                  DataTable dt = (DataTable)JsonConvert.DeserializeObject(json, (typeof(DataTable)));
                  return dt;
              }
          }
      

提交回复
热议问题