可能的问题是来自mysql

时间:2019-02-21 05:24:28

标签: vb.net

我试图将更改保存在datagridview中,但是当我单击“保存”按钮时,显示“更新成功”的消息框。但是在我的mysql数据库中没有进行任何更改。

Imports MySql.Data.MySqlClient
Public Class Intake

Dim conn As MySqlConnection
Dim comm As MySqlCommand

Dim dr As MySqlDataReader
Dim dbDataset As New DataTable


Public Sub FilterData(valueToSearch As String)
        Try
            conn = New MySqlConnection
            conn.ConnectionString = "server=localhost;userid=root;password=SOUTHEAST;database=reportingsystem"
            Dim searchquery As String = "Select intDate as 'Date', intTimeStart as 'Time Start', intTimeEnd as 'Time End', intDownTime as 'Down Time', intWaitingTime as 'Waiting Time', intReturn as 'Returns', intTOT as 'Total Operating Time', intTRT as 'Total Running Time', intReportBy as 'Report by', intSupervisedBy as 'Supervised by' FROM reportingsystem.intake WHERE CONCAT(intDate, intTimeStart, intTimeEnd, intDownTime, intWaitingTime, intReturn, intTOT, intTRT) like '%" & valueToSearch & "%'"

        Dim commander As New MySqlCommand(searchquery, conn)
        Dim adapter As New MySqlDataAdapter(commander)
        Dim dbDataset As New DataTable()

        adapter.Fill(dbDataset)

        IntakeDGV.DataSource = dbDataset

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    FilterData(TextBox2.Text)
End Sub

Private Sub Modify_Click(sender As Object, e As EventArgs) Handles Modify.Click


    dgvSave.Enabled = True
    dgvCancel.Enabled = True



End Sub

Private Sub dgvSave_Click(sender As Object, e As EventArgs) Handles dgvSave.Click

    Dim SaveBtn As String = "Select * FROM reportingsystem.intake"

    Dim commander As New MySqlCommand(SaveBtn, conn)
    Dim adapter As New MySqlDataAdapter(commander)
    Dim table As New DataTable()

    Try
        IntakeDGV.EndEdit()
        Dim cb As New MySqlCommandBuilder(adapter)
        adapter.Update(table)

        MsgBox("Update successful")

        dgvSave.Enabled = False
        dgvCancel.Enabled = False
    Catch ex As Exception
        MsgBox("Update failed")
    End Try

End Sub

结束班级

1 个答案:

答案 0 :(得分:0)

尝试一下:

Try
    ExtruderDataGrid.EndEdit()
    Dim cb As New MySqlCommandBuilder(adapter)
    adapter.Update(table)

    MsgBox("Update successful")

    dgvSave.Enabled = False
    dgvCancel.Enabled = False
Catch ex As Exception
    MsgBox("Update failed")
End Try