0

SQL Server 2012の型を持つ列をDateTimeWCF DataContract C# クラスとSqlDataReader. 最初に変換する必要がありますか?それがインターフェースにあるという事実は違いを生みますか?

WCF サービスは、asp.net グリッド ビューの a に代わるものであり、そこSqlConnectionに関するすべての情報について混乱しており、DateTimeこれまでに理解したことから、C#DateTimeでは実際のデータ型なので、これはどのように機能しますか。

それを文字列にすると、それはできないと言われるので、この時点で何をしますか? これを理解するのに役立つだけでなく、私がどのルートをたどることができるかを見るのを手伝ってくれてありがとう。

イライラして無知なリンダ

これは私のInvoiceDBクラスです

namespace AbbeyRoadServiceLibrary
{
   [DataObject(true)]
   public class InvoiceDB
   {
      [DataObjectMethod(DataObjectMethodType.Select)]
      public static List<Invoice> GetInvoices(string customerid)
      {
          List<Invoice> invoiceList = new List<Invoice>();

          SqlConnection con = AbbeyRoadDB.GetConnection();

          SqlCommand cmd = new SqlCommand();
          cmd.CommandText = "select InvoiceNum,InvoiceDate,InvoiceTotal,Job,Status from Invoices where CustomerID = @CustomerID order by InvoiceNum";
          cmd.CommandType = CommandType.Text;
          cmd.Connection = con;
          cmd.Parameters.AddWithValue("@CustomerID", customerid);

          try
          {
              con.Open();
              SqlDataReader reader = cmd.ExecuteReader();

              while (reader.Read())
              {
                  Invoice i = new Invoice();
                  i.InvoiceNum = reader[0].ToString();
             // Thought I was to convert it but no happy code results from doing this in this  way!!
                  i.InvoiceDate = Convert.ToDateTime(reader[1]); 
                  i.InvoiceTotal = Convert.ToDecimal(reader[2]);
                  i.Job = reader[3].ToString();
                  i.Status = reader[4].ToString();

                  invoiceList.Add(i);
              }
              reader.Close();
          }
          catch (SqlException ex)
          {
              throw ex;
          }
          finally
          {
              con.Close();
          }

          return invoiceList;
      }
   }
}

私のインターフェースコードは主に重要な部分です!

public interface InterfaceInvoiceService
{
    [OperationContract]
    List<Customer> GetCustomer();

    [OperationContract]
    List<Invoice> GetInvoices(string customerid);
}

[DataContract]
public class Invoice
{
    string invoiceID = "";
    string invoicedate = "";  //I know this is not right but see below
    decimal invoicetotal = 0m;
    string job = "";
    string status ="";

    [DataMember]
    public string InvoiceNum
    {
        get { return invoiceID; }
        set { invoiceID = value; }
    }

    [DataMember]
    public DateTime InvoiceDate
    {
        get { return invoicedate; } // here it says that it cannot implicitly convert it to a string on return and value.
        set { invoicedate = value; }
    }

    [DataMember]
    public decimal InvoiceTotal
    {
        get { return invoicetotal; }
        set { invoicetotal = value; }
    }

    [DataMember]
    public string Job
    {
        get { return job; }
        set { job = value; }
    }
4

2 に答える 2