Click to See Complete Forum and Search --> : Problem With DateTime


maverick786us
September 27th, 2007, 07:06 AM
I am facing a small problem while picking date from a textbox and converting it into DateTime.

The problem lies over here

objCertificate.InstallDate = Convert.ToDateTime(txtInstallDate.Text, DtInfo).Date;


Since I am using JavaScript calander control to pick up date. So I have made these textBoxese as read only. If I make readonly false. It does'nt create any problem. But because I enabled read only so that no user can add date wrong date the format therefore I made it read only, but it throws this error.


String was not recognized as a valid DateTime.

PeejAvery
September 27th, 2007, 07:48 AM
You can alter the read-only boolean whenever you need to make a change.

maverick786us
September 27th, 2007, 07:51 AM
You can alter the read-only boolean whenever you need to make a change.

I might use it as my 2ndary inititative. But what could be the reason for this problem??

PeejAvery
September 27th, 2007, 08:00 AM
It seems to me that read-only is acting as disabled for you. But so long as it is not read-only it works for you?

maverick786us
September 27th, 2007, 08:22 AM
It seems to me that read-only is acting as disabled for you. But so long as it is not read-only it works for you?

yes it works, and yes with read-only it acts as disabled but. When i tried to display its value using Response.Write it gets displayed.

PeejAvery
September 27th, 2007, 09:19 AM
So then can you post all of the relevant code?

maverick786us
September 28th, 2007, 12:35 AM
So then can you post all of the relevant code?

Here it is


System.Globalization.CultureInfo DtInfo = new System.Globalization.CultureInfo("en-AU");
DtInfo.DateTimeFormat.ShortDatePattern = "MM/dd/yyyy";



try
{
objCertificate.InstallDate = Convert.ToDateTime(txtInstallDate.Text, DtInfo).Date;
objCertificate.NotifyDate = Convert.ToDateTime(txtNotifyDate.Text, DtInfo).Date;
objCertificate.ExpireDate = Convert.ToDateTime(txtExpireDate.Text, DtInfo).Date;
}
catch
{
objCertificate.InstallDate = DateTime.Now.Date;
objCertificate.NotifyDate = DateTime.Now.Date;
objCertificate.ExpireDate =DateTime.Now.Date;
}

objCertificate is an Object of ClsCertificate Class and

private DateTime _installDate;
public DateTime InstallDate
{
get { return _installDate; }
set { _installDate = value; }
}

private DateTime _expireDate;
public DateTime ExpireDate
{
get { return _expireDate; }
set { _expireDate = value; }
}

private DateTime _notifyDate;
public DateTime NotifyDate
{
get { return _notifyDate; }
set { _notifyDate = value; }
}


Here is the code to set the properties in the class and


public short UpdateCertificates()
{
SqlParameter[] objParam = new SqlParameter[14];

objParam[0] = new SqlParameter("@Certificate_ID", SqlDbType.BigInt);
objParam[1] = new SqlParameter("@Issue_Authority", SqlDbType.VarChar, 100);
objParam[2] = new SqlParameter("@Cert_Type", SqlDbType.VarChar, 100);
objParam[3] = new SqlParameter("@Req_Authority", SqlDbType.VarChar, 100);
objParam[4] = new SqlParameter("@Install_Date", SqlDbType.DateTime);
objParam[5] = new SqlParameter("@Expire_Date", SqlDbType.DateTime);
objParam[6] = new SqlParameter("@Notify_Date", SqlDbType.DateTime);
objParam[7] = new SqlParameter("@Department", SqlDbType.SmallInt);
objParam[8] = new SqlParameter("@user_name", SqlDbType.VarChar, 50);
objParam[9] = new SqlParameter("@Computer_ID", SqlDbType.VarChar, 50);
objParam[10] = new SqlParameter("@Certificate_Code", SqlDbType.VarChar, 50);
objParam[11] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
objParam[12] = new SqlParameter("@Notes", SqlDbType.VarChar, 500);
objParam[13] = new SqlParameter("@Updation", SqlDbType.Bit);

objParam[0].Value = _certificateid;
objParam[1].Value = _issueauthority;
objParam[2].Value = _certificatetype;
objParam[3].Value = _requestingauthority;
objParam[4].Value = _installDate;
objParam[5].Value = _expireDate;
objParam[6].Value = _notifyDate;
objParam[7].Value = _department;
objParam[8].Value = _userid;
objParam[9].Value = _pcid;
objParam[10].Value = _certificateid;
objParam[11].Value = _password;
objParam[12].Value = _notes;
objParam[13].Value = _updation;

object Resultset = objManager.ExecuteScalarQuery("dbWBS_usp_UpdateCertificateDetails", objParam);
return Convert.ToInt16(Resultset);
}


This is where the procedure is actually called

PeejAvery
September 28th, 2007, 08:06 AM
Unfortunately, that doesn't really show much. I did some searching and came up with the following links. See if some of those help you out.

http://forums.asp.net/t/671457.aspx
http://www.velocityreviews.com/forums/t21049-string-was-not-recognized-as-a-valid-datetime.html

Also, can you verify that the actual value is being set when it is read-only? Or is it not even altering?