Ekrem Tapan

Ekrem Tapan

  • NA
  • 967
  • 81.7k

Insert dateTime Problem

Oct 6 2015 2:43 AM
hi everybody, 
 
i want to insert mysql datetime, sometimes i will input but sometimes i dont wanna input any date  
 
below is my code
 
but not working
 
 
Dim sqldatenull As SqlDateTime
Using Cmd As New MySqlCommand
Cmd.CommandText = "INSERT INTO Data (SBID ,SiteID ,MainSID ,AreaID ,ContentType ,Title ,URL ,Targets ,Files ,ViewCount ,Filess ,Contents ,DisplaySDate ,DisplayEDate) VALUES (?SBID ,?SiteID ,?MainSID ,?AreaID ,?ContentType ,?Title ,?URL ,?Targets ,?Files ,?ViewCount,?Filess ,?Contents ,DisplaySDate ,DisplayEDate)"
Cmd.Parameters.Add(New MySqlParameter("?SBID", SBID))
Cmd.Parameters.Add(New MySqlParameter("?SiteID", SiteID))
Cmd.Parameters.Add(New MySqlParameter("?MainSID", MainSID))
Cmd.Parameters.Add(New MySqlParameter("?AreaID", AreaID))
Cmd.Parameters.Add(New MySqlParameter("?ContentType", ContentType))
Cmd.Parameters.Add(New MySqlParameter("?Title", Title))
Cmd.Parameters.Add(New MySqlParameter("?URL", URL))
Cmd.Parameters.Add(New MySqlParameter("?Targets", Targets))
Cmd.Parameters.Add(New MySqlParameter("?Files", Files))
Cmd.Parameters.Add(New MySqlParameter("?Filess", Filess))
Cmd.Parameters.Add(New MySqlParameter("?Contents", Contents))
Cmd.Parameters.Add(New MySqlParameter("?ViewCount", ViewCount))
sqldatenull = SqlDateTime.Null
If (DisplaySDate.ToString() = "") Then
Cmd.Parameters.Add(New MySqlParameter("?DisplaySDate", DisplaySDate)).Value = sqldatenull
Else
Cmd.Parameters.Add(New MySqlParameter("?DisplaySDate", DisplaySDate))
End If
If (DisplayEDate.ToString() = "") Then
Cmd.Parameters.Add(New MySqlParameter("?DisplayEDate", DisplayEDate)).Value = sqldatenull
Else
Cmd.Parameters.Add(New MySqlParameter("?DisplayEDate", DisplayEDate))
End If
 
i have a this error
 
http://oi60.tinypic.com/ops1d.jpg 
 
 this is a inputbox get set code 
 
Public Property DisplaySDate() As DateTime
Get
DisplaySDate = Me.txtDisplaySDate.Text
End Get
Set(value As DateTime)
Me.txtDisplaySDate.Text = value
End Set
End Property
Public Property DisplayEDate() As DateTime
Get
DisplayEDate = Me.txtDisplayEDate.Text
End Get
Set(value As DateTime)
Me.txtDisplayEDate.Text = value
End Set
End Property
 
 
 
 

Answers (5)