How to insert DBnull to nullable DateTime field asp.net c# -


Do I need to insert null in a square field date time? This is the class:

  Public time data for the public {public int TD_ID {get; Set; } Public Full UD_ID {get; Set; } Public Date Time? TD_start {get; Set; } Public Date Time? TD_end {get; Set; } Public Date Time? Timestamp {receive; Set; } Enter public Zero (Int TD_ID, int UD_ID, datetime? Td_start, datetime? Td_end, datetime? Timestamp) {this.TD_ID = TD_ID; This.UD_ID = UD_ID; This.TD_start = TD_start; This.TD_end = TD_end; This.timestemp = Timestamp; }}  

I have accessed SQL Server using the stored procedures from a page. Some returns values ​​in the datetime field are empty and return as DBANL, which can not be stored in the timetable? I can see the return value with lots but I like to find it more elegant way to work. SQL Server Connection:

  Try {string strConnString = ConfigurationManager.ConnectionStrings ["Achi"]. ConnectionString; System.Data.SqlClient.SqlConnection SQLCon = New System.Data.SqlClient.SqlConnection (); SqlDataReader myReader = Default (SqlDataReader); SQLCon = New SqlConnection (strConnString); SqlCommand sqlCmd = New SqlCommand ("usp_TD_select_last_record_By_UD_ID", SQLCon); SqlCmd.Parameters.AddWithValue ("@UD_ID", user.UD_ID); SqlCmd.CommandType = CommandType.StoredProcedure; SQLCon.Open (); If (SQLCon.State == ConnectionState.Open) {myReader = sqlCmd.ExecuteReader (); If (myReader.HasRows) {while (myReader.Read ()) {timeData.Insert (Convert.ToInt32 (myReader ["TD_ID"]. ToString ()), Convert.ToInt32 (myReader ["UD_ID"]. ToString () Convert Tundetime (My Reader ["TD_start"]), Convert.Todetime (My Reader ["TD_and"]), Convert.Todetime (My Reader ["TD_TimeStamp"])); }} And {newLine = true; } MyReader.Close (); SQLCon.Close (); }} Hold (Exception pre) {east; }  

And the table in DB looks like this:

  [TD_ID] [int] detection (1,1) No tap, [UD_ID] [ Int] zero, [TD_start] [datetime] zero, [TD_end] [datetime] zero, [TD_timestemp] [datetime] zero,  

You may have a helpful type of this type:

  public static t getValue & LT; T & gt; (This IDataRecord record, string name) {var index = record.GetOrdinal (name); Return Records ISDN Bull (index)? Default (T): (T) record. Gate value (index); }  

And then it says:

  timeData.Insert (myReader.GetValue & lt; integer & gt; ("TD_ID"), .. .. myReader.GetValue & lt; date time? & Gt; ("TD_timestemp"), ...);  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -