简体   繁体   English

使用vb.net在Mysql中插入特定日期

[英]Insert a specific date in Mysql using vb.net

Okay here is the scenario, I need to insert a specific date in mysql. 好的,这是场景,我需要在mysql中插入一个特定的日期。 Everytime I insert this date I get 0000-00-00. 每次输入此日期,我都会得到注册。

Everytime a user pays between the 1st and the 20th of the month then the wb_due-date column would increment the month by 1 每次用户在每月的1号到20号之间付款,则wb_due-date列会将月份增加1

Ex. 例如 I have a default value of wb_paid-date = 2013-10-15 and wb_due-date = 2013-10-20 . 我的默认值为wb_paid-date = 2013-10-15 and wb_due-date = 2013-10-20 Now User1 Paid on 2013-10-15 and after I clicked button, the date saved on wb_due-date was 0000-00-00 instead of 2013-11-20 现在,User1于2013-10-15支付,当我单击按钮后,保存在wb_due-date上的日期为0000-00-00而不是2013-11-20

Take a look at my code 看看我的代码

Function iterate(ByVal d As Date) As String
        Dim m As Integer = d.Month
        If d.Month >= 1 And d.Month <= 11 Then
            m += 1
        ElseIf d.Month = 12 Then
            m = 1
        End If
        Return m
    End Function

cmd = New MySqlCommand("INSERT INTO tbl_billing(wb_paid-date, wb_due-date) 
VALUES(CURDATE(), iterate(Now.Date) , con)

First, let's fix your function: 首先,让我们修复您的功能:

Function iterate(ByVal d As DateTime) As String
    Return d.AddMonths(1).ToString("yyyy-MM-dd")
End Function

Also, if you're putting a string date into command, you're almost certainly doing something wrong. 另外,如果您要在命令中输入字符串日期,则几乎可以肯定是做错了什么。 Let's just do this: 让我们这样做:

Function iterate(ByVal d As DateTime) As DateTime
    Return d.AddMonths(1)
End Function

Then we'll fix your Sql Command: 然后,我们将修复您的Sql命令:

cmd = New MySqlCommand("INSERT INTO tbl_billing(wb_paid-date, wb_due-date) VALUES(CURDATE(), ? " , con)
cmd.Parameters.Add("?", SqlDbType.DateTime).Value = iterate(Today)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM