【问题标题】:How to put Query on the list with c# visual Studio?如何使用 c# Visual Studio 将 Query 放在列表中?
【发布时间】:2020-08-31 16:48:57
【问题描述】:

这是我的类 (getProductItem),用于从 Query 中获取数据并将其设置在 SAP Crystal Report 上:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp1
{
    public class getProductItem
    {
        public static int nomor = 0;
        public int No
        {
            get
            {
                return getProductItem.nomor++; 
            }
        }
        public string nama_produk { get; set; }
        public string harga_satuan { get; set; }
        public string jumlah_penjualan { get; set; }
        public string total_harga { get; set; }

    }
}

这是我的问题,我必须用 .Query 改变什么,我最终遇到了错误。 'MySqlConnection' does not contain a definition for 'Query' and no accesible edtension method 'Query'accepting a first argument of type 'MySqlConnection'could be found (are you missing a using directive or an assembly reference?)

我正在学习使用 SQL 数据库的教程,但我使用的是 mysql 数据库。所以我不知道如何解决它。

顺便说一句,下面的代码来自另一个 windows 窗体,它设置了一个查询来获取数据并将其放在getProductItem 的列表中,但它并不顺利

using (MySqlConnection dbConn = new MySqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
{
  dbConn.Open();
  string insertQuery = "SELECT  p.nama_produk, d.harga_satuan, d.jumlah_penjualan, d.total_harga FROM detail_penjualan_produk d JOIN produk p ON p.id_produk = d.id_produk WHERE d.id_penjualan = '" + UCTransaction.IDPenjualan + "' ";
  List<getProductItem> list = dbConn.Query<getProductItem>(insertQuery, CommandType: CommandType.Text).ToList();
}

【问题讨论】:

  • 你遇到了什么错误?请提供一些具体信息。
  • 对不起,现在你又可以在上面看到了,我只是把它放在错误信息中

标签: c# mysql visual-studio


【解决方案1】:

也许你需要先安装Nuget包Dapper,并添加一个using语句。

using ...
using Dapper;
using ...

【讨论】:

  • 你是对的。它确实解决了这个问题。非常感谢
  • @Ellie 如果这对您有帮助,请点击 将其标记为答案。
猜你喜欢
  • 1970-01-01
  • 2015-02-18
  • 2011-08-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-16
  • 1970-01-01
相关资源
最近更新 更多