Cannot implicitly convert type 'System.DBNull' to 'System.DateTime'


I'm using

_StartDate = DBNull.Value;

 _StartDate is datetime

Somehow its not working when I set to dbnull.value

Error 1 Cannot implicitly convert type 'System.DBNull' to 'System.DateTime' 

 i want to set to null or empty, how do i do that?

 thanks.


Its all about coding!
0
nisarkhan
11/29/2006 4:59:58 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

2 Replies
3565 Views

Similar Articles

[PageSpeed] 47
Get it on Google Play
Get it on Apple App Store

Dear,

the DateTime datatype cannot be null. that is why ur getting this kind of error

what u can do is to set the default value for the DateTime variable that u have to the DateTime.MinValue. it will give u a date (1/1/0001) which for sure you can depend on.

Happy coding


Haissam Abdul Malak
MCAD.NET
| Blog |
0
Haissam
11/29/2006 6:56:37 PM

habibi sukran ;)

 i figured out after i post.


Its all about coding!
0
nisarkhan
11/29/2006 7:04:52 PM
Reply:

Similar Artilces:

Datetime for Inserts
 Hello all Is there a way to do this, or is there a better way?public static DateTime DateTimeForInsert(DateTime myDateTime) { if (myDateTime == DateTime.MinValue || myDateTime == DateTime.MinValue || myDateTime.ToString().Length > 0) { return DBNull.Value; } return myDateTime; }     Cannot implicitly convert type 'System.DBNull' to 'System.DateTime'Remember to click “Mark as Answer” on the post if it helped you. Thank you! You should use nullable types.   public static DateTime? DateTimeForInsert(DateTime? d) {  &nb...

Object of type 'System.DBNull' cannot be converted to type 'System.DateTime'.
Hi, How can I pass null values to a system.datetime? Thanks in advance for the help J   Below is my code:   Public Class Courses     Public Sub Update_Class(ByVal ClassId As Integer, _    ByVal StatusId As Integer, _    ByVal ClassNumber As Integer, _    ByVal TeacherId As Integer, _    ByVal AmountofParticipants As Integer, _    ByVal CourseDate1 As DateTime, _    ByVal CourseDate2 As DateTime, _    ByVal CourseDate3 As DateTime)     Dim myConnection As New SqlConnection(Conn...

Convert 'System.DBNull' to type 'System.String' ?
I have a textbox on my site that I want to populate with some data, however when the value is null, which is quite often.The problem is that when I call a static method which returns a string; when that string is DBNull, I get the following error which is absolutely correct.Unable to cast object of type 'System.DBNull' to type 'System.String'.So, what should I do to be able to ignore that the string is null and just display a "" string in the texbox?The code is as follows:    private void GetCartSmall(string sSessionID)    {      &n...

System.Net.Mail is giving error CS0029: Cannot implicitly convert type 'string' to 'System.Net.Mail.MailAddress'
I'm getting an error while trying to use the wizard to create a form and than pass it the vaibles to Mail. Any help would be much appreciated. SmtpClient smtpClient = new SmtpClient(); MailMessage message = new MailMessage(); try {   message.From = txtEmail.Text; message.To.Add("admin1@yoursite.com"); message.Subject = "Feedback"; message.CC.Add("admin1@yoursite.com"); message.CC.Add("admin2@yoursite.com"); message.IsBodyHtml = false; message.Body = txtMessage.Text; smtpClient.Send(message); lblStatus.Text = "Email successfully sent."; } catch (Exception ex) { lbl...

ASPNET2 HELP! CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'.
Server Error in '/start-movieposters' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0266: Cannot implicitly convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.FileUpload'. An explicit conversion exists (are you missing a cast?) Source Error: ...

Object of type 'System.DBNull' cannot be converted to type 'System.String' from formview
I have a formview that I am using for input to my datatable.  I am using an objectdatasource that uses a BLL.  This in turn points to my XSD tableadapter. When I test, and only fill in the required fields, I am getting the error Object of type 'System.DBNull' cannot be converted to type 'System.String' I am not sure what field is having the issue.  In my BLL for the Add, I have checked the dates for null and placed the value of DateTime.MinValue.  For the text fields, I have place "" if they are null.  Is this error being create prior to...

cannot implicitly convert type 'System.DateTime' to 'bool'
I get the error "cannot implicitly convert type 'System.DateTime' to 'bool' ". I couldn't find out from where i get this error.Code in .aspx:<asp:Calender id="calSchedule" onDayRender="calScheduleRender_DayRender" runat="server" />//Retrieve the EntryDate from database<ItemTemplate>        <h2>Date: <%# Eval("EntryDate", "{0:D}") %></h2>        <%# Eval("Entry") %></ItemTemplate>Code in .aspx....

Cannot implicitly convert type 'int' to 'System.DateTime'
Hi,This is my asp.net coding DateTime dt = Convert.ToInt32( TextBox5.Text);            DateTime dt1 = Convert.ToString(TextBox6.Text); I am execute the coding this error coming. Cannot implicitly convert type 'int' to 'System.DateTime'  What you are trying to do? if in textbox5 you are entering a date and u want to save it in dt variable use the below code DateTime dt = Convert.ToDateTime(TextBox5.Text); DateTime dt1 = Convert.ToDateTime(TextBox6.Text); if it didnt work, please specify what you are entering as data in Text...

Cannot implicitly convert type 'string' to 'System.DateTime'
Hi, I have a DateTime field in my sql server database. The field can take null value. In my aspx page, i have a textbox to get the input from the user. If the textbox value is empty, how to handle it? This is my cs code: objMyTime.StartTime = DateTime.Parse(txtStartTime.Text);   I am getting error as: "Cannot implicitly convert type 'string' to 'System.DateTime' " Thank you  seems to me objMyTime.StartTime is a string and ur trying to assign the datetime.try with this objMyTime.StartTime = DateTime.Parse(txtStartTime.Text).ToString();use RequiredFi...

Value of type 'System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap'.
 Hello,         I receive this error "System.Web.UI.Control' cannot be converted to 'System.Web.SiteMap" when I try to find the Sitemap control.  ...            <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />            <asp:ListView ID="ListView1" runat="server">            <LayoutTemplate>    ...

Value of type 'System.Net.Mail.MailMessage' cannot be converted to 'System.Net.Mail.AlternateView'
Trying to create an alternateview to send a txt email with the html formatted email.  I've used string builder to create the whole email, but I get this error.  Any ideas why?  i've bolded the line that throws the error... Dim EmailBodyTxt As New StringBuilder EmailBodyTxt.Append("<html><style type='text/css'>.table{border:solid; border-color:#006666; width:600;} ")EmailBodyTxt.Append("<body><table class='table'><tr><td colspan='2'><h1>Test<br />RESPONSE SYSTEM</h1></td>...

Cannot implicitly convert type 'System.Xml.XmlNode' to 'XmlNode' and 'XmlNode' does not contain a definition for 'AppendChild'
Hi,      XmlNode t = xmlDoc.SelectSingleNode("/NewDataSet/Table1/Template");//Cannot implicitly convert type 'System.Xml.XmlNode' to 'XmlNode'//        XmlText textNode1 = xmlDoc.CreateTextNode("hello");                       XmlElement ChildofTemplate = xmlDoc.CreateElement("ChildTemplate");//'XmlNode' does not contain a definition for 'AppendChild'// ...

Error: Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField'
Hello, I am getting the following error during compiliation. Any suggestions to fix it. Thanks. Cannot convert type 'System.Web.UI.Control' to 'System.Web.UI.WebControls.ButtonField' protected void gvEvents_RowCommand(Object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow selectedRow = gvEvents.Rows[index]; string sID; ButtonField btn; if (selectedRow.RowType == DataControlRowType.DataRow) { sID = ((ButtonField)selectedRow.FindControl("ID")).DataTextFi...

Cannot implicitly convert type 'System.Data.DataTable' to 'System.Data.Dataset'
I am using an excel spreadsheet as a data source to build a dataset which is then used to populate a grid:  I am getting the following error: Cannot implicitly convert type 'System.Data.DataTable' to 'System.Data.Dataset' Here's my code:private DataSet GetData(String description, String mpnumber, String link) { //MPData will represents the Data in Application Cache. We will use Cache Data //for performance purposes, because MP Information will not change often. I choose // to also use Dataset Filtering instead of SQL Server Filtering. However the DataAccess l...

Web resources about - Cannot implicitly convert type 'System.DBNull' to 'System.DateTime' - asp.net.web-forms

Resources last updated: 1/13/2016 3:01:54 PM