Archive for May, 2011

May 11, 2011

Passing NULL values to SQL Server, SQLDateTime and DateTIme

DateTime.MinValue indicates a NULL value in .NET. When you tried to insert the same to SQL Server you will come up with an over flow error saying only allowed values are in between the range 1/1/1753 to 12/31/9999. But in .NET the DateTime type can accept the date time values in between 0:00 1/1/000 (MinValue) and 23:59 12/31/9999 (MaxValue). That is why we are getting the error “SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM”.

The work around would be like this : if you need to pass NULL value to a datetime field from the .NET code behind pass the DateTime.Min value to the variable, and then at the time of assigning the same to SQL parameter check for that DateTime.Min value and assign the DBNull.Value when inserting.


if (strStartDate.Contains("1/1/0001 12:00:00 AM"))
 {
 comm.Parameters.Add(new SqlParameter("@startDate", SqlDbType.VarChar)).Value = DBNull.Value;
 }
 else
 {
 comm.Parameters.AddWithValue("@startDate", Employee.StartDate);
 }

Advertisements
May 11, 2011

DevExpress : Cannot unregister UpdatePanel with ID ‘UpdatePanel1’

I was using the DevExpress tab control and was suddenly came across the error : “Cannot unregister UpdatePanel with ID ‘UpdatePanel1’ since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported. Parameter name: updatePanel”

the solution to the above error instead of the line


tabControl.TabPages['abc"].Visible = false;

//Or setting

tabControl.TabPages['abc"].Enabled = false;

change to


tabControl.TabPages['abc"].ClientVisible = false;

//Or setting

tabControl.TabPages['abc"].ClientEnabled = false;

refer this link for more details.