2016-07-28 23 views
0

DateTimeの代わりにstring型のパラメータを使用している.Net C#に問題があります。DataSetの代わりにDateTimeの代わりにデフォルトの文字列

データベース列は、型(SQL)の「日付」です。

「文字列RptDate」を「DateTime RptDate」に手動で変更することはできますが、完全に機能しますが、データセットを変更すると、デザイナーコードが再生成され、変更を上書きします。

パラメータを特定のタイプにするにはどうすればよいですか?

// this is system generated code from the "Dataset.Designer.cs" file 
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 
     [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")] 
     [global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")] 
     [global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Select, false)] 
     public virtual prDataSet.DetailedRow1DataTable GetDataByUserDate(string RptDate, string UserID) { // this first parameter should be DateTime 
      this.Adapter.SelectCommand = this.CommandCollection[1]; 
      if ((RptDate == null)) { 
       throw new global::System.ArgumentNullException("RptDate"); 
      } 
      else { 
       // This next line should cast the value as DateTime 
       this.Adapter.SelectCommand.Parameters[0].Value = ((string)(RptDate)); 
      } 
      if ((UserID == null)) { 
       throw new global::System.ArgumentNullException("UserID"); 
      } 
      else { 
       this.Adapter.SelectCommand.Parameters[1].Value = ((string)(UserID)); 
      } 
      prDataSet.DetailedRow1DataTable dataTable = new prDataSet.DetailedRow1DataTable(); 
      this.Adapter.Fill(dataTable); 
      return dataTable; 
     } 

SQLクエリコード:

SELECT 
    id, category, rpt_date, user_id, details, last_modified 
FROM   
    DetailedRow 
WHERE  
    (rpt_date = @RptDate) AND (user_id LIKE @UserID) 

データベースのコード作成:

CREATE TABLE [dbo].[DetailedRow] 
(
    [id] [int] IDENTITY(100000,1) NOT NULL, 
    [category] [int] NOT NULL, 
    [rpt_date] [date] NOT NULL, 
    [user_id] [nvarchar](6) NOT NULL, 
    [details] [ntext] NOT NULL, 
    [last_modified] [datetime] NOT NULL, 

    CONSTRAINT [PK_DetailedRow] 
     PRIMARY KEY CLUSTERED ([id] ASC) 
      WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
       IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, 
       ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] 
GO 

ALTER TABLE [dbo].[DetailedRow] 
    ADD CONSTRAINT [DF_DetailedRow_last_modified] 
     DEFAULT (getdate()) FOR [last_modified] 
GO 

答えて

1

を私がチェックしたい最初のものは、データセットデザイナのGUIバージョンです。 DataTableのrpt_dateフィールドがDateTimeであることを確認するだけです

+0

デザイナのDataTableのrpt_date列のデータ型はSystem.DateTimeです。 –

+0

私は、クエリのパラメータコレクション内のパラメータのデータ型を変更することができました。私はそれが戻って戻ってくるかどうかを確認するために別のクエリを追加するまで待たなければならないが、今のところそれを修正したようだ。 –

関連する問題