Vb net update statement问题

时间:2018-04-02 16:09:24

标签: vb.net-2010

我在SQL server中有插入和更新值的vb.net项目。它的sql代码如下:

    Public Sub insert_customer_new(ByVal customer_id As Integer, ByVal work_state As Integer)
    Dim cmd As New SqlCommand("insert into customer_tbl (customer_id , work_state ) values (@customer_id, @work_state )", conn)
    cmd.Parameters.Add("customer_id", SqlDbType.Int).Value = customer_id
    cmd.Parameters.Add("work_state", SqlDbType.Int).Value = work_state
    If conn.State = ConnectionState.Open Then conn.Close()
    conn.Open()
    cmd.ExecuteNonQuery()
    conn.Close()
    cmd = Nothing
End Sub

然后

    Public Sub update_customer_new(ByVal customer_id As Integer, ByVal work_state As Integer)
    Dim cmd As New SqlCommand("update customer_tbl set  work_state = @work_state where customer_id = @customer_id ", conn)
    cmd.Parameters.Add("customer_id", SqlDbType.Int).Value = customer_id
    cmd.Parameters.Add("work_state", SqlDbType.Int).Value = work_state
    If conn.State = ConnectionState.Open Then conn.Close()
    conn.Open()
    cmd.ExecuteNonQuery()
    conn.Close()
    cmd = Nothing
End Sub

我使用 Button.Click事件 表示insert

Private Sub insert_customer_Click(sender As Object, e As EventArgs) Handles insert_customer.Click
    If customer_id.Text = String.Empty Then
        MsgBox("Pleas Enter Customer Number")
        customer_id.Focus()
    ElseIf state_txt.Text = String.Empty Then
        MsgBox("Pleas Enter The Start State Number ")
        state_txt.Focus()
    Else
        insert_customer_new(customer_id.Text, state_txt.Text)
        MsgBox("Insert Done !")
    End If

End Sub

同样地,我使用 Button.Click事件 表示update

Private Sub update_state_Click(sender As Object, e As EventArgs) Handles update_state.Click
    If customer_id.Text = String.Empty Then
        MsgBox("Pleas Enter Customer Number For Update")
        customer_id.Focus()
    ElseIf state_txt.Text = String.Empty Then
        MsgBox("Pleas Enter The New State Number ")
        state_txt.Focus()
    Else
        update_customer_new(customer_id.Text, state_txt.Text)
        MsgBox("Update Done !")
    End If
End Sub

问题是update语句不执行的某个时间。它没有给出错误,并且过程只是因为未知原因而跳过此行。 发布申请后,所有案例中约占10%。

0 个答案:

没有答案