object datasource使用get返回0和空值;组;数据库映射C#时使用dapper orm

时间:2017-11-08 21:28:57

标签: c# dapper

  

我尝试将数据从SQL服务器检索到gridView控件中,但是在我的第一列中获取0值,在第二列中获取空列。我的映射类从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; }
}
  

这部分是我执行从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);
            }
        }
    }
  

这里概述了我运行项目时发生的事情。   enter image description here

和sql server中的数据。 enter image description here

1 个答案:

答案 0 :(得分:2)

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

声明如下:

proc sql;
  select count(Name) into :NumOfDatasets from Datas;
  select Name into :Dataset1-:Dataset%trim(%left(&NumOfDatasets)) from datas;
quit;

%do index = 1 %to &NumOfDatasets;

  proc contents data=&ImportLibrary..&&Dataset&index.
                out=&ExportLibrary..&&Dataset&index.;
  run;

  proc sort data=&ExportLibrary..&&Dataset&index.;
    by varnum;
  run;

  proc export data=&ExportLibrary..&&Dataset&index.(keep=name label)
              outfile="&ExportLocation"
              dbms=excelcs
              replace;
    sheet="&&Dataset&index";
  run;
%end;