Kan ikke gemme en dato.
Jeg har lavet en frontend til en ms sql database her skal jeg gemme nogle atributter herunder en dato. Det kan jeg ikke, jeg kan godt læse datoen ind, så der er hul igennem. Jeg har også kunnet gemme datoer, men så lavede jeg et eller andet og nu kan jeg ikke.Her er koden til den del som skal gemme:
Public Class frmOpretKomtar
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.Button1 = New System.Windows.Forms.Button
Me.Label5 = New System.Windows.Forms.Label
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(144, 24)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.TextBox1.Size = New System.Drawing.Size(272, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(32, 28)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(56, 16)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Emne"
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(144, 56)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(272, 20)
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = ""
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(32, 60)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(72, 16)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Navn"
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(144, 88)
Me.TextBox3.Multiline = True
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.Size = New System.Drawing.Size(272, 56)
Me.TextBox3.TabIndex = 4
Me.TextBox3.Text = ""
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(32, 96)
Me.Label3.Name = "Label3"
Me.Label3.TabIndex = 5
Me.Label3.Text = "Adresse"
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(144, 160)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.Size = New System.Drawing.Size(272, 20)
Me.TextBox4.TabIndex = 6
Me.TextBox4.Text = ""
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(32, 200)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(80, 16)
Me.Label4.TabIndex = 7
Me.Label4.Text = "Kommentar"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(192, 392)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(184, 24)
Me.Button1.TabIndex = 8
Me.Button1.Text = "Gem Kommentar"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(32, 160)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(80, 16)
Me.Label5.TabIndex = 9
Me.Label5.Text = "Email"
'
'TextBox5
'
Me.TextBox5.Location = New System.Drawing.Point(144, 208)
Me.TextBox5.Multiline = True
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.Size = New System.Drawing.Size(272, 168)
Me.TextBox5.TabIndex = 10
Me.TextBox5.Text = ""
'
'frmOpretKomtar
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(472, 430)
Me.Controls.Add(Me.TextBox5)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox1)
Me.Name = "frmOpretKomtar"
Me.Text = "OpretKommentar"
Me.ResumeLayout(False)
End Sub
#End Region
Dim komment As New Kommentarklas
Dim resultat As New DataSet
Private Sub frmOpretKomtar_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = True
Me.Hide()
End Sub
Sub opretkommentar(ByVal idnr As Integer)
komment.SubjectId = idnr
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
komment.Adr = TextBox3.Text
komment.Body = TextBox5.Text
komment.CommentDateTime = Now
komment.Email = TextBox4.Text
komment.Header = TextBox1.Text
komment.Name = TextBox2.Text
SQLinsert("insert into Comment(subjectid,header,body,name,adr,email,commentdatetime) values (" & komment.SubjectId & ",'" & komment.Header & "','" & komment.Body & "','" & komment.Name & "','" & komment.Adr & "','" & komment.Email & "'," & komment.CommentDateTime & ")")
Kommentarer.Indlæskommentarer()
Kommentarer.Show()
OpretKomtar.Close()
End Sub
End Class
jeg har lavet en sub SQLinsert som indeholder adgang til databasen.
I Klassen kommentarklas er CommentDateTime erklæret som date
her er den fejl meddelse der kommer
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
Hvad gør jeg galt