对象数据源 returns 0 和使用 get 的空值;放;使用 dapper orm 时的数据库映射 C#

object datasource returns 0 and empty values using get; set; database mapping C# while using dapper orm

I'm trying to retrieve data from SQL server into a gridView Control, but however get 0 values in my first column and an empty column in my second column. My mapping class to get data from sql server:

    public class classInvoiceNumberSQL
{
    public  int RowNumber { get; set; }
    public int invoiceNumber { get; set; }
    public DateTime InvoiceDate { get; set; }
    public string CustomerID { get; set; }
    public double InvoiceTotal { get; set; }
}

And this part is where i execute to pull through the data from sql

        private void btnLoadByDate_Click(object sender, EventArgs e)
    {
        using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["Invo_X.P.Properties.Settings.conSQL"].ConnectionString))
        {
            if (db.State == ConnectionState.Closed)
            {
                db.Open();
                string query = "Select RowLines, invoiceNumber, InvoiceDate, CustomerID, invoiceTotal From tblInvoiceNumber";
                classInvoiceNumberSQLBindingSource.DataSource = db.Query<classInvoiceNumberSQL>(query, commandType: CommandType.Text);
            }
        }
    }

Here an overview of whats happening when i run the project. enter image description here

以及 sql 服务器中的数据。 enter image description here

你的映射有误。您的数据库中有 RowLines,但 DTO 中有 RowNumber。

声明如下:

public class classInvoiceNumberSQL
{
    public  int RowLines { get; set; }
    public int invoiceNumber { get; set; }
    public DateTime InvoiceDate { get; set; }        
    public string CustomerID { get; set; }
    public double InvoiceTotal { get; set; }
}