Click here to Skip to main content
15,891,864 members

get date value from datetimepicker and store date into database but not with time!!

donaldliaw87 asked:

Open original thread
pros and master out there please have a look on my code, i do not how to solve my problem regarding to get (datevalue) and insert into database, i had try my best to custom code them out but the inserted (datevalue) still with time '12:00:00'. please help me!!!


Form load part
Private Sub Admin_and_GA_Matter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        DateTimePicker1.Format = DateTimePickerFormat.Custom
        DateTimePicker1.CustomFormat = "dd MMM yyyy"
         DateTimePicker2.Format = DateTimePickerFormat.Custom
        DateTimePicker2.CustomFormat = "dd MMM yyyy"

    End Sub


insert part

Private Sub insertinto()

       Dim insert1 As String = "INSERT INTO AGITbl (CreateBy, StartDate, CloseDate, StartTime, CloseTime, Contentx, Remark, Status, ShowOnB) VALUES (@CreateBy, @StartDate, @CloseDate, @StartTime, @CloseTime, @Contentx, @Remark, @Status, @ShowOnB)"
       Dim cmd As New SqlCommand(insert1, connection)
       cmd.Parameters.AddWithValue("@CreateBy", Label10.Text.Trim)

       cmd.Parameters.AddWithValue("@StartDate", DateTimePicker1.Value.ToShortDateString)
       cmd.Parameters.AddWithValue("@CloseDate", DateTimePicker2.Value.ToShortDateString)

       cmd.Parameters.AddWithValue("@StartTime", DateTimePicker3.Value.ToShortTimeString)
       cmd.Parameters.AddWithValue("@CloseTime", DateTimePicker4.Value.ToShortTimeString)
       cmd.Parameters.AddWithValue("@Contentx", RichTextBox1.Text.Trim)
       cmd.Parameters.AddWithValue("@Remark", RichTextBox2.Text.Trim)
       cmd.Parameters.AddWithValue("@Status", Label7.Text.Trim)
       cmd.Parameters.AddWithValue("@ShowOnB", CInt(Label9.Text))

       If RichTextBox1.Text = "" And RichTextBox2.Text = "" And Label7.Text = "" And Label9.Text = 2 Then
           MsgBox("blank content not allow to send")
       ElseIf RichTextBox1.Text IsNot Nothing And RichTextBox2.Text IsNot Nothing And Label7.Text IsNot Nothing And Label9.Text <> 2 Then
           If connection.State = ConnectionState.Closed Then
               connection.Open()
           End If
           cmd.ExecuteNonQuery()
           MsgBox("Information sent")
           connection.Close()
           RichTextBox1.Text = ""
           RichTextBox2.Text = ""
           Label7.Text = ""
           Label9.Text = ""
           Me.RadioButton1.Checked = False
           Me.RadioButton2.Checked = False
           Me.RadioButton3.Checked = False
           Me.RadioButton4.Checked = False
           Me.RadioButton5.Checked = False
       End If


additional load out codes:

VB
Public Sub loadalll()
        Dim sqlq As String = "SELECT * FROM AGITbl"
        Dim sqlcmd As New SqlCommand
        Dim sqladpt As New SqlDataAdapter
        Dim tbl As New DataTable

        With sqlcmd
            .CommandText = sqlq
            .Connection = connection
        End With

        With sqladpt
            .SelectCommand = sqlcmd
            .Fill(tbl)
        End With

        DataGridView1.Rows.Clear()
        For i = 0 To tbl.Rows.Count - 1
            With DataGridView1
                .Rows.Add(tbl.Rows(i)("AGINO"), tbl.Rows(i)("CreateBy"), tbl.Rows(i)("StartDate"), tbl.Rows(i)("CloseDate"), tbl.Rows(i)("StartTime"), tbl.Rows(i)("CloseTime"), tbl.Rows(i)("Contentx"), tbl.Rows(i)("Remark"), tbl.Rows(i)("Status"), tbl.Rows(i)("ShowOnB"))
            End With
        Next
        connection.Close()
    End Sub


A normal load out, show on datagridview!!!
Tags: Visual Basic

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900