Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have taken all date value as date in database but when i give value 09/11/2014..its accepting but when i give value in -30/10/2014..its giving this kind of error..why..need help...please suggest solution i am begginer..
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'TODO:add data into data base If ComboBox1.Text <> "" Then Dim ab As Long ab = random.Next("10000", "99999")
VB
        Dim date1 As Date = Date.ParseExact(TextBox3.Text, "dd/MM/yyyy", Nothing).Date
        Dim date2 As Date = Date.ParseExact(TextBox4.Text, "dd/MM/yyyy", Nothing).Date
        Dim date3 As Date = Date.ParseExact(TextBox5.Text, "dd/MM/yyyy", Nothing).Date
        'Dim date3 As Date = Date.Parse(TextBox5.Text)
        Dim date4 As Date = Date.ParseExact(TextBox6.Text, "dd/MM/yyyy", Nothing).Date

        If Button1.Enabled = False Then
            If TextBox11.Text <> "" And ComboBox1.Text <> "" And TextBox2.Text <> "" And TextBox3.Text <> "" And TextBox4.Text <> "" Then
                TextBox10.Text = ab
                cm.Close()
                cm.Open()
                ComboBox1.Text = Replace(ComboBox1.Text, "'", "''")
                TextBox1.Text = Replace(TextBox1.Text, "'", "''")
                TextBox7.Text = Replace(TextBox7.Text, "'", "''")
                TextBox6.Text = Now.Date.ToString("dd/MM/yyyy")
                TextBox8.Text = DateTime.Now.ToString("HH:mm:ss")
                cmd.CommandText = "insert into worker(faccno,fname,faddr,famcdue,fjoindate,fdate,fattended,fproblem,fsolution,fstatus,fremark,fassign,findate,fintime,fserviceno,falert)values ('" & TextBox11.Text & "', '" & ComboBox1.Text & "','" & TextBox2.Text & "','" & date1.ToString("dd/MM/yyyy") & "','" & date2.ToString("dd/MM/yyyy") & "','" & date3.ToString("dd/MM/yyyy") & "','" & ComboBox4.Text & "','" & TextBox1.Text & "','" & TextBox7.Text & "','" & ComboBox2.Text & "','" & ComboBox6.Text & "','" & ComboBox5.Text & "','" & date4 & "','" & TextBox8.Text & "','" & TextBox10.Text & "','" & ComboBox3.SelectedIndex & "')"
                cmd.ExecuteNonQuery()
                MessageBox.Show("Information Insertion sucessfull", "Save")
                MessageBox.Show(ab, "your service no is")
                Button7.PerformClick()
                cm.Close()
            Else
                MessageBox.Show("enter all values then try to save information", "error")
                Exit Sub
            End If
        ElseIf ComboBox1.Text <> "" Then
            cm.Close()
            cm.Open()
            TextBox1.Text = Replace(TextBox1.Text, "'", "''")
            TextBox7.Text = Replace(TextBox7.Text, "'", "''")
            TextBox6.Text = Now.Date.ToString("dd/MM/yyyy")
            TextBox8.Text = DateTime.Now.ToString("HH:mm:ss")
            ComboBox4.Text = Replace(ComboBox4.Text, "'", "''") 'TODO:this code replaces single quotes to store in data base
            cmd.CommandText = "update worker set faccno= '" & TextBox11.Text & "', fname='" & ComboBox1.Text & "',faddr='" & TextBox2.Text & "',famcdue='" & date1 & "',fjoindate='" & date2 & "',fdate='" & date3 & "',fattended='" & ComboBox4.Text & "',fproblem='" & TextBox1.Text & "',fsolution=  '" & TextBox7.Text & "',fstatus='" & ComboBox2.Text & "',fremark='" & ComboBox6.Text & "',fassign= '" & ComboBox5.Text & "',findate='" & date4 & "',fintime='" & TextBox8.Text & "',fserviceno='" & TextBox10.Text & "',falert='" & ComboBox3.SelectedIndex & "' where fserviceno='" & TextBox10.Text & "'"
            cmd.ExecuteNonQuery()
            MessageBox.Show(" Information Updation sucessfull", "Save")
            Button7.PerformClick()
            cm.Close()
        End If
    Else
        MessageBox.Show("enter all values then try to save information", "error")
        Exit Sub
    End If

End Sub
Posted
Updated 10-Nov-14 18:33pm
v3

1 solution

VB
Public Class Form1
    Dim dateString As String
    Dim dateValue As Date
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        dateValue = Date.Today
        dateString = Convert.ToString(dateValue)
        MessageBox.Show(dateString)
    End Sub
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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