Note that there are some explanatory texts on larger screens.

plurals
  1. POInvalid Cast DateTime?
    primarykey
    data
    text
    <p>I have a class with the following code</p> <pre><code> public cCase(string pCaseNo, string pMode) { if (pMode == "new") { this._caseNo = Validate_CaseNo(pCaseNo); } if (pMode == "existing") { try { int intValidatedCaseNo = Validate_CaseNo(pCaseNo); string sqlText = "SELECT * FROM tblCases WHERE CaseNo = @CaseNo;"; string strConnection = cConnectionString.BuildConnectionString(); SqlConnection linkToDB = new SqlConnection(strConnection); linkToDB.Open(); SqlCommand sqlCom = new SqlCommand(sqlText, linkToDB); sqlCom.Parameters.Add("@CaseNo", SqlDbType.Int); sqlCom.Parameters["@CaseNo"].Value = intValidatedCaseNo; SqlDataReader caseReader = sqlCom.ExecuteReader(); if (caseReader.HasRows) while (caseReader.Read()) { this._claimant = caseReader["Claimant"].ToString(); this._defendant = caseReader["Defendant"].ToString(); this._caseType = caseReader["CaseType"].ToString(); this._occupation = caseReader["Occupation"].ToString(); this._doa = (DateTime?)caseReader["DOA"]; this._dateClosed = (DateTime?)caseReader["DateClosed"]; this._dateSettled = (DateTime?)caseReader["DateSettled"]; this._dateInstructed = (DateTime?)caseReader["DateInstructed"]; this._status = caseReader["Status"].ToString(); this._instructionType = caseReader["InstructionType"].ToString(); this._feeEstimate = (decimal?)caseReader["FeeEstimate"]; this._amountClaimed = (decimal?)caseReader["AmountClaimed"]; this._amountSettled = (decimal?)caseReader["AmountSettled"]; this._caseManager = caseReader["CaseManager"].ToString(); } caseReader.Close(); linkToDB.Close(); linkToDB.Dispose(); } catch (Exception eX) { throw new Exception("Error finding case" + Environment.NewLine + eX.Message); } } } </code></pre> <p>However the Datetime? casts fail with an 'Invalid Cast'. I've checked the SQL database and the field is storing valid dates So I cant work out why, as I extract info via the DataReader into my app, the datetime fields are causing an Invalid Cast.</p> <p>Please help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload