none
如何让用户可以追踪到货品的出货与退还记录 RRS feed

  • 问题

  • 我正在篇写一个程序是有关用户可以追踪到货品的出货与退还记录,但是有关记录方面的状态我不知应该怎么篇写希望各位给帮忙非常感谢。

    以下是我篇写的出货记录与access数据库的资料。

    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
          

                    Dim cmd As New OleDb.OleDbCommand
                    If Not cnn.State = ConnectionState.Open Then
                        'open connection if it is not open yet
                        cnn.Open()
                    End If
                    cmd.Connection = cnn
                    'check whether add new or update
                    If Me.txtCID.Tag & "" = "" Then
                        'add new 
                        'add data to mydatatable
                        cmd.CommandText = "INSERT INTO tbl_Info([CBCID],[LineNo],[Date],[Location],[OtherLocation],[PIC],[OtherPIC],[Reason],[Remarks]) " &
                        "VALUES('" & dgvData("cbcid", dgvData.CurrentCell.RowIndex).Value & "', '" & Me.txtline.Text & "', '" & Me.DateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss") & "', '" & Me.txtLocation.Text & "', '" & Me.txtOlocation.Text & "','" & Me.txtPIC.Text & "','" & Me.txtOtherPIC.Text & "','" & Me.txtReason.Text & "','" & Me.txtRemarks.Text & "')"
                        ''"VALUES('" & Me.txtCID.Text & "' , '" & Me.txtline.Text & "', '" & Me.DateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss") & "', '" & Me.txtLocation.Text & "', '" & Me.txtOlocation.Text & "','" & Me.txtPIC.Text & "','" & Me.txtotherPIC.Text & "','" & Me.txtReason.Text & "','" & Me.txtRemarks.Text & "')"


                        'error message before save data fill textbox
                        If txtline.Text.Trim = "" Or txtLocation.Text.Trim = "" Or txtPIC.Text.Trim = "" Then
                            MessageBox.Show("Please Insert Data", "Error Message")
                            Exit Sub
                        End If

                        cmd.ExecuteNonQuery()

                        MsgBox("Add Data Successful", MsgBoxStyle.OkOnly, "Message")

                    Else


                        'error message before save data fill textbox
                        If txtline.Text.Trim = "" Or txtRemarks.Text.Trim = "" Then
                            MessageBox.Show("Please Insert Data", "Error Message")
                            Exit Sub
                        End If

                        cmd.CommandText = "UPDATE tbl_Info " & _
                                    " SET" & _
                                    "  [LineNo]='" & Me.txtline.Text & "'" & _
                                    ", [Date]='" & Me.DateTimePicker1.Text & "'" & _
                                    ", [Location]='" & Me.txtLocation.Text & "'" & _
                                    ", [OtherLocation]='" & Me.txtOlocation.Text & "'" & _
                                    ", [PIC]='" & Me.txtPIC.Text & "'" & _
                                    ", [OtherPIC]='" & Me.txtOtherPIC.Text & "'" & _
                                    ", [Resason]='" & Me.txtReason.Text & "'" & _
                                    ", [Remarks]='" & Me.txtRemarks.Text & "'" & _
                                    " WHERE [cid]=" & Me.txtCID.Tag
                        MsgBox("Update Data Successful", MsgBoxStyle.OkOnly, "Message")


                        cmd.ExecuteNonQuery()
                    End If
                    'refresh data in list
                    RefreshData1()
                    'clear form
                    Me.btnClear.PerformClick()
                    'close connection
                    cnn.Close()
        End Sub

    2019年9月3日 5:11

全部回复

  • Hi christing,

    >>但是有关记录方面的状态我不知应该怎么篇写希望各位给帮忙非常感谢。

    我看了你的数据库表,但是我并没有看到有关记录状态的字段。所以,我的建议是你需要添加有关新的字段(例如status),一旦货物售出,状态会发生改变。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年9月3日 6:28
    版主
  • @Jack J Jun

    我已经在我的tbl_Info 加入了status

    接下来我应该怎么让用户按send 按键或return按键时制动把send 或return 按键存入在tbl_Info数据库里的status呢!


    2019年9月3日 6:52
  • @Jack J Jun

    我已经在我的tbl_Info 加入了status

    接下来我应该怎么让用户按send 按键或return按键时制动把send 或return 按键存入在tbl_Info数据库里的status呢!


    你可以使用update语句来做到这件事情。

    当你点击Send按钮时:

      string sql = "update tbl_Info set Status=send where ...";

    当你点击return按钮时:

     string sql = "update tbl_Info set Status=return where ...";

    如果你对sql更新语句不是太了解,你可以参照以下链接。

    SQL UPDATE Statement

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年9月3日 7:02
    版主
  • @Jack J Jun 

    已下是我篇改过后的CODE但我还是无法储存我Send 的字眼在我的tbl_Info 的数据库.我是否少做了什么导致send字眼无法储存进数据库

    cmd.CommandText = "INSERT INTO tbl_Info([CBCID],[LineNo],[Date],[Location],[OtherLocation],[PIC],[OtherPIC],[Reason],[Remarks]) " &
                        "VALUES('" & dgvData("cbcid", dgvData.CurrentCell.RowIndex).Value & "', '" & Me.txtline.Text & "', '" & Me.DateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss") & "', '" & Me.txtLocation.Text & "', '" & Me.txtOlocation.Text & "','" & Me.txtPIC.Text & "','" & Me.txtOtherPIC.Text & "','" & Me.txtReason.Text & "','" & Me.txtRemarks.Text & "')"

    cmd.CommandText = "UPDATE tbl_Info " & _
                            " SET" & _
                          "  [LineNo]='" & Me.txtline.Text & "'" & _
                          ", [Date]='" & Me.DateTimePicker1.Text & "'" & _
                          ", [Location]='" & Me.txtLocation.Text & "'" & _
                          ", [OtherLocation]='" & Me.txtOlocation.Text & "'" & _
                          ", [PIC]='" & Me.txtPIC.Text & "'" & _
                          ", [OtherPIC]='" & Me.txtOtherPIC.Text & "'" & _
                          ", [Resason]='" & Me.txtReason.Text & "'" & _
                          ", [Remarks]='" & Me.txtRemarks.Text & "'" & _
                          ", [Status]='Send" & _
                          " WHERE [CBCID]=" & Me.txtCID.Tag

    cmd.CommandText = "UPDATE tbl_Info " & _
                            " SET" & _
                          "  [LineNo]='" & Me.txtline.Text & "'" & _
                          ", [Date]='" & Me.DateTimePicker1.Text & "'" & _
                          ", [Location]='" & Me.txtLocation.Text & "'" & _
                          ", [OtherLocation]='" & Me.txtOlocation.Text & "'" & _
                          ", [PIC]='" & Me.txtPIC.Text & "'" & _
                          ", [OtherPIC]='" & Me.txtOtherPIC.Text & "'" & _
                          ", [Resason]='" & Me.txtReason.Text & "'" & _
                          ", [Remarks]='" & Me.txtRemarks.Text & "'" & _
                          ", [Status]='Send' " & _
                          " WHERE [cid]=" & Me.txtCID.Tag

      
    2019年9月3日 8:17
  • Hi christing,

    我检查了你的代码,我发现你在send后面少了一个添加单引号,你可以添加这个单引号来解决这个问题。

      Dim sql As String = "UPDATE tbl_Info " &
                            " SET" &
                          "  [LineNo]='" & "test1" & "'" &
                          ", [Date]='" & "test1" & "'" &
                          ", [Location]='" & "test1" & "'" &
                          ", [OtherLocation]='" & "test1" & "'" &
                          ", [PIC]='" & "test1" & "'" &
                          ", [OtherPIC]='" & "test1" & "'" &
                          ", [Resason]='" & "test1" & "'" &
                          ", [Remarks]='" & "test1" & "'" &
                          ", [Status]='Send" & "'" &
                          " WHERE [CBCID]=" & "test1"

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年9月3日 8:32
    版主
  • @Jack J Jun 感谢你的回复

    我尝试使用过几种方法篇写。但还是无法把 SEND 字眼成功储存到tbl_Info数据库中。

    以下是我尝试的code

    ", [Status]='Send' " & "'" & _

    ", [Status]=Send " & "'" & _

    ", [Status]=Send " & "'" & _


    2019年9月3日 9:08
  • Hi 

    我又有了新的发现,你在where语句中也有问题。

    代码:

     Dim sql As String = "UPDATE tbl_Info " &
                            " SET" &
                          "  [LineNo]='" & "test1" & "'" &
                          ", [Date]='" & "test1" & "'" &
                          ", [Location]='" & "test1" & "'" &
                          ", [OtherLocation]='" & "test1" & "'" &
                          ", [PIC]='" & "test1" & "'" &
                          ", [OtherPIC]='" & "test1" & "'" &
                          ", [Resason]='" & "test1" & "'" &
                          ", [Remarks]='" & "test1" & "'" &
                          ", [Status]='Send" & "'" &
                          " WHERE [CBCID]=" & "'" & "test1" & "'"

    如果所料不错,你应该得到以下结果。

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2019年9月3日 9:17
    版主