问题:从字符串vb.net转换日期和/或时间时转换失败

时间:2017-10-19 04:15:10

标签: sql sql-server vb.net visual-studio

我已经制作了名为" ComeGo"在SQL Server中通过MS Visual Studio,它有12列

并且有代码:

(
    [CGID] INT NOT NULL PRIMARY KEY, 
    [CGDate] DATETIME2 NULL, 
    [CGTime] DATETIME2 NULL, 
    [CGUserName] NVARCHAR(MAX) NULL, 
    [CGComeDate] DATETIME2 NULL, 
    [CGComeTime] DATETIME2 NULL, 
    [CGComeNotes] NVARCHAR(MAX) NULL, 
    [CGGODate] DATETIME2 NULL, 
    [CGGOTime] DATETIME2 NULL, 
    [CGGONotes] NVARCHAR(MAX) NULL, 
    [CGDefference] NVARCHAR(MAX) NULL, 
    [ActionBy] NVARCHAR(MAX) NULL 
)

现在我调试那段代码:

    Dim ComeGoCheck As String
    ComeGoCheck = "SELECT COUNT(*) FROM ComeGo WHERE CGUserName=@CGUserName AND CGGoDate=@CGGoDate"
    Dim cmd As SqlCommand = New SqlCommand(ComeGoCheck, Con)
    Dim query As Integer
    cmd.Parameters.Add("@CGUserName", SqlDbType.VarChar).Value = GoForm_CGUserName_TextBox.Text
    cmd.Parameters.Add("@CGGoDate", SqlDbType.Date).Value = GoForm_CGGoDate_DateTimePicker.Value
    Con.Open()
    query = CInt(cmd.ExecuteScalar())
    Con.Close()
    If query > 0 Then
        MsgBox("لقد تم تسجيل انصراف الموظف مسبقا")
        Con.Close()
    Else
        GoForm_DataGridView(7, GoForm_DataGridView.CurrentRow.Index).Value = Now.Date
        GoForm_DataGridView(8, GoForm_DataGridView.CurrentRow.Index).Value = Now
        'Count TimeDiff Between DateCome And DateGo
        GoForm_DataGridView(10, GoForm_DataGridView.CurrentRow.Index).Value = DateDiff(DateInterval.Minute, GoForm_DataGridView(5, GoForm_DataGridView.CurrentRow.Index).Value, GoForm_DataGridView(8, GoForm_DataGridView.CurrentRow.Index).Value) / 60
        ComeGoCMD = New SqlCommand(" Update ComeGo SET 
                    CGDefference = " & GoForm_DataGridView(10, GoForm_DataGridView.CurrentRow.Index).Value & ",
                    CGGODate = '" & GoForm_DataGridView(7, GoForm_DataGridView.CurrentRow.Index).Value & "',
                    CGGOTime = '" & GoForm_DataGridView(8, GoForm_DataGridView.CurrentRow.Index).Value & "',
                    CGGONotes = '" & GoForm_DataGridView(9, GoForm_DataGridView.CurrentRow.Index).Value & "' 
                    where 
                    CGID = " & GoForm_DataGridView(0, GoForm_DataGridView.CurrentRow.Index).Value & "", Con)
        Con.Open()
        ComeGoCMD.ExecuteNonQuery()
        Con.Close()
        'Show Message Box
        MsgBox("User Go Registred")
        'Reload ComeGo Table With New UpDates
        Load_ComeGo()
        Con.Close()
    End If

我收到错误:

ComeGoCMD.ExecuteNonQuery()

并说:

  从字符串

转换日期和/或时间时,

转换失败

0 个答案:

没有答案