Public Class frmEdit
Public connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;data source=" & System.AppDomain.CurrentDomain.BaseDirectory & "\oopdb.accdb"
Public conn As New OleDb.OleDbConnection
Sub loadListView()
With ListView1
.FullRowSelect = True
.MultiSelect = False
.View = View.Details
.Columns.Clear()
.Items.Clear()
.Columns.Add("Router ID", 50, HorizontalAlignment.Left)
.Columns.Add("Serial", 100, HorizontalAlignment.Left)
.Columns.Add("Model", 100, HorizontalAlignment.Left)
.Columns.Add("Remarks", 100, HorizontalAlignment.Left)
.Columns.Add("DateChecked", 100, HorizontalAlignment.Left)
End With
With ListView2
.FullRowSelect = True
.MultiSelect = False
.View = View.Details
.Columns.Clear()
.Items.Clear()
.Columns.Add("Switch ID", 50, HorizontalAlignment.Left)
.Columns.Add("Serial", 100, HorizontalAlignment.Left)
.Columns.Add("Model", 100, HorizontalAlignment.Left)
.Columns.Add("Ports", 100, HorizontalAlignment.Left)
.Columns.Add("Remarks", 100, HorizontalAlignment.Left)
.Columns.Add("DateChecked", 100, HorizontalAlignment.Left)
End With
With ListView3
.FullRowSelect = True
.MultiSelect = False
.View = View.Details
.Columns.Clear()
.Items.Clear()
.Columns.Add("Cable ID", 50, HorizontalAlignment.Left)
.Columns.Add("Type", 100, HorizontalAlignment.Left)
.Columns.Add("Model", 100, HorizontalAlignment.Left)
.Columns.Add("Remarks", 100, HorizontalAlignment.Left)
.Columns.Add("DateChecked", 100, HorizontalAlignment.Left)
End With
With ListView4
.FullRowSelect = True
.MultiSelect = False
.View = View.Details
.Columns.Clear()
.Items.Clear()
.Columns.Add("Device ID", 50, HorizontalAlignment.Left)
.Columns.Add("Type", 100, HorizontalAlignment.Left)
.Columns.Add("Model", 100, HorizontalAlignment.Left)
.Columns.Add("Remarks", 100, HorizontalAlignment.Left)
.Columns.Add("DateChecked", 100, HorizontalAlignment.Left)
End With
With ListView5
.FullRowSelect = True
.MultiSelect = False
.View = View.Details
.Columns.Clear()
.Items.Clear()
.Columns.Add("Monitor ID", 50, HorizontalAlignment.Left)
.Columns.Add("Serial", 100, HorizontalAlignment.Left)
.Columns.Add("Model", 100, HorizontalAlignment.Left)
.Columns.Add("Size", 100, HorizontalAlignment.Left)
.Columns.Add("Remarks", 100, HorizontalAlignment.Left)
.Columns.Add("DateChecked", 100, HorizontalAlignment.Left)
End With
With ListView6
.FullRowSelect = True
.MultiSelect = False
.View = View.Details
.Columns.Clear()
.Items.Clear()
.Columns.Add("CPU ID", 50, HorizontalAlignment.Left)
.Columns.Add("Serial", 100, HorizontalAlignment.Left)
.Columns.Add("Model", 100, HorizontalAlignment.Left)
.Columns.Add("Remarks", 100, HorizontalAlignment.Left)
.Columns.Add("DateChecked", 100, HorizontalAlignment.Left)
End With
Dim sqlq1 As String = "SELECT * FROM Router"
Dim sqlq2 As String = "SELECT * FROM Switch"
Dim sqlq3 As String = "SELECT * FROM Cables"
Dim sqlq4 As String = "SELECT * FROM Devices"
Dim sqlq5 As String = "SELECT * FROM Monitor"
Dim sqlq6 As String = "SELECT * FROM CPU"
Dim sqlcomm1 As New OleDb.OleDbCommand
Dim sqlcomm2 As New OleDb.OleDbCommand
Dim sqlcomm3 As New OleDb.OleDbCommand
Dim sqlcomm4 As New OleDb.OleDbCommand
Dim sqlcomm5 As New OleDb.OleDbCommand
Dim sqlcomm6 As New OleDb.OleDbCommand
Dim sqladpt1 As New OleDb.OleDbDataAdapter
Dim sqladpt2 As New OleDb.OleDbDataAdapter
Dim sqladpt3 As New OleDb.OleDbDataAdapter
Dim sqladpt4 As New OleDb.OleDbDataAdapter
Dim sqladpt5 As New OleDb.OleDbDataAdapter
Dim sqladpt6 As New OleDb.OleDbDataAdapter
Dim table1 As New DataTable
Dim table2 As New DataTable
Dim table3 As New DataTable
Dim table4 As New DataTable
Dim table5 As New DataTable
Dim table6 As New DataTable
With sqlcomm1
.CommandText = sqlq1
.Connection = conn
End With
With sqlcomm2
.CommandText = sqlq2
.Connection = conn
End With
With sqlcomm3
.CommandText = sqlq3
.Connection = conn
End With
With sqlcomm4
.CommandText = sqlq4
.Connection = conn
End With
With sqlcomm5
.CommandText = sqlq5
.Connection = conn
End With
With sqlcomm6
.CommandText = sqlq6
.Connection = conn
End With
With sqladpt1
.SelectCommand = sqlcomm1
.Fill(table1)
End With
With sqladpt2
.SelectCommand = sqlcomm2
.Fill(table2)
End With
With sqladpt3
.SelectCommand = sqlcomm3
.Fill(table3)
End With
With sqladpt4
.SelectCommand = sqlcomm4
.Fill(table4)
End With
With sqladpt5
.SelectCommand = sqlcomm5
.Fill(table5)
End With
With sqladpt6
.SelectCommand = sqlcomm6
.Fill(table6)
End With
For i = 0 To table1.Rows.Count - 1
With ListView1
.Items.Add(table1.Rows(i)("ID"))
With .Items(.Items.Count - 1).SubItems
.Add(table1.Rows(i)("Serial"))
.Add(table1.Rows(i)("Model"))
.Add(table1.Rows(i)("Remarks"))
.Add(table1.Rows(i)("DateChecked"))
End With
End With
Next
For i = 0 To table2.Rows.Count - 1
With ListView2
.Items.Add(table2.Rows(i)("ID"))
With .Items(.Items.Count - 1).SubItems
.Add(table2.Rows(i)("Serial"))
.Add(table2.Rows(i)("Model"))
.Add(table2.Rows(i)("Ports"))
.Add(table2.Rows(i)("Remarks"))
.Add(table2.Rows(i)("DateChecked"))
End With
End With
Next
For i = 0 To table3.Rows.Count - 1
With ListView3
.Items.Add(table3.Rows(i)("ID"))
With .Items(.Items.Count - 1).SubItems
.Add(table3.Rows(i)("Type"))
.Add(table3.Rows(i)("Remarks"))
.Add(table3.Rows(i)("DateChecked"))
End With
End With
Next
For i = 0 To table4.Rows.Count - 1
With ListView4
.Items.Add(table4.Rows(i)("ID"))
With .Items(.Items.Count - 1).SubItems
.Add(table4.Rows(i)("Type"))
.Add(table4.Rows(i)("Model"))
.Add(table4.Rows(i)("Remarks"))
.Add(table4.Rows(i)("DateChecked"))
End With
End With
Next
For i = 0 To table5.Rows.Count - 1
With ListView5
.Items.Add(table5.Rows(i)("ID"))
With .Items(.Items.Count - 1).SubItems
.Add(table5.Rows(i)("Serial"))
.Add(table5.Rows(i)("Model"))
.Add(table5.Rows(i)("Size"))
.Add(table5.Rows(i)("Remarks"))
.Add(table5.Rows(i)("DateChecked"))
End With
End With
Next
For i = 0 To table6.Rows.Count - 1
With ListView6
.Items.Add(table6.Rows(i)("ID"))
With .Items(.Items.Count - 1).SubItems
.Add(table6.Rows(i)("Serial"))
.Add(table6.Rows(i)("Model"))
.Add(table6.Rows(i)("Remarks"))
.Add(table6.Rows(i)("DateChecked"))
End With
End With
Next
End Sub
Private Sub frmView_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
conn.ConnectionString = connstring
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
loadListView()
End Sub
Dim id As Integer
Private Sub ListView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseClick
Dim sqlquery1 As String = "SELECT * FROM Router"
Dim sqlcom1 As New OleDb.OleDbCommand
Dim sqladpt1 As New OleDb.OleDbDataAdapter
Dim t1 As New DataTable
With sqlcom1
.CommandText = sqlquery1
.Connection = conn
End With
With sqladpt1
.SelectCommand = sqlcom1
.Fill(t1)
End With
If ListView1.SelectedItems.Count Then
id = ListView1.SelectedItems(0).Text
roserial.Text = ListView1.SelectedItems(0).SubItems(1).Text
romodel.Text = ListView1.SelectedItems(0).SubItems(2).Text
roremarks.Text = ListView1.SelectedItems(0).SubItems(3).Text
rodate.Text = ListView1.SelectedItems(0).SubItems(4).Text
End If
End Sub
Private Sub ListView2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView2.SelectedIndexChanged
Dim sqlquery2 As String = "SELECT * FROM Switch"
Dim sqlcom2 As New OleDb.OleDbCommand
Dim sqladpt2 As New OleDb.OleDbDataAdapter
Dim t2 As New DataTable
With sqlcom2
.CommandText = sqlquery2
.Connection = conn
End With
With sqladpt2
.SelectCommand = sqlcom2
.Fill(t2)
End With
If ListView2.SelectedItems.Count Then
id = ListView2.SelectedItems(0).Text
swserial.Text = ListView2.SelectedItems(0).SubItems(1).Text
swmodel.Text = ListView2.SelectedItems(0).SubItems(2).Text
swport.Text = ListView2.SelectedItems(0).SubItems(3).Text
swremarks.Text = ListView2.SelectedItems(0).SubItems(4).Text
swdate.Text = ListView2.SelectedItems(0).SubItems(5).Text
End If
End Sub
Private Sub ListView3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView3.SelectedIndexChanged
Dim sqlquery3 As String = "SELECT * FROM Cables"
Dim sqlcom3 As New OleDb.OleDbCommand
Dim sqladpt3 As New OleDb.OleDbDataAdapter
Dim t3 As New DataTable
With sqlcom3
.CommandText = sqlquery3
.Connection = conn
End With
With sqladpt3
.SelectCommand = sqlcom3
.Fill(t3)
End With
If ListView3.SelectedItems.Count Then
id = ListView3.SelectedItems(0).Text
caserial.Text = ListView3.SelectedItems(0).SubItems(1).Text
caremarks.Text = ListView3.SelectedItems(0).SubItems(2).Text
cadate.Text = ListView3.SelectedItems(0).SubItems(3).Text
End If
End Sub
Private Sub ListView4_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView4.SelectedIndexChanged
Dim sqlquery4 As String = "SELECT * FROM Devices"
Dim sqlcom4 As New OleDb.OleDbCommand
Dim sqladpt4 As New OleDb.OleDbDataAdapter
Dim t4 As New DataTable
With sqlcom4
.CommandText = sqlquery4
.Connection = conn
End With
With sqladpt4
.SelectCommand = sqlcom4
.Fill(t4)
End With
If ListView4.SelectedItems.Count Then
id = ListView4.SelectedItems(0).Text
devtype.Text = ListView4.SelectedItems(0).SubItems(1).Text
devmodel.Text = ListView4.SelectedItems(0).SubItems(2).Text
devremarks.Text = ListView4.SelectedItems(0).SubItems(3).Text
devdate.Text = ListView4.SelectedItems(0).SubItems(4).Text
End If
End Sub
Private Sub ListView5_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView5.SelectedIndexChanged
Dim sqlquery5 As String = "SELECT * FROM Monitor"
Dim sqlcom5 As New OleDb.OleDbCommand
Dim sqladpt5 As New OleDb.OleDbDataAdapter
Dim t5 As New DataTable
With sqlcom5
.CommandText = sqlquery5
.Connection = conn
End With
With sqladpt5
.SelectCommand = sqlcom5
.Fill(t5)
End With
If ListView5.SelectedItems.Count Then
id = ListView5.SelectedItems(0).Text
monser.Text = ListView5.SelectedItems(0).SubItems(1).Text
monmod.Text = ListView5.SelectedItems(0).SubItems(2).Text
monsize.Text = ListView5.SelectedItems(0).SubItems(3).Text
monrem.Text = ListView5.SelectedItems(0).SubItems(4).Text
mondate.Text = ListView5.SelectedItems(0).SubItems(5).Text
End If
End Sub
Private Sub ListView6_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView6.SelectedIndexChanged
Dim sqlquery6 As String = "SELECT * FROM CPU"
Dim sqlcom6 As New OleDb.OleDbCommand
Dim sqladpt6 As New OleDb.OleDbDataAdapter
Dim t6 As New DataTable
With sqlcom6
.CommandText = sqlquery6
.Connection = conn
End With
With sqladpt6
.SelectCommand = sqlcom6
.Fill(t6)
End With
If ListView6.SelectedItems.Count Then
id = ListView6.SelectedItems(0).Text
cpser.Text = ListView6.SelectedItems(0).SubItems(1).Text
cpmod.Text = ListView6.SelectedItems(0).SubItems(2).Text
cprem.Text = ListView6.SelectedItems(0).SubItems(3).Text
cpdate.Text = ListView6.SelectedItems(0).SubItems(4).Text
End If
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Try
Dim sqlquer1 As String = "UPDATE Router SET Serial = '" & roserial.Text & "', Model = '" & romodel.Text & "', Remarks = '" & roremarks.Text & "', DateChecked = '" & rodate.Text & "', WHERE ID = " & id & ""
Dim sqlcom1 As New OleDb.OleDbCommand
With sqlcom1
.CommandText = sqlquer1
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("UPDATE SUCCESSFUL")
loadListView()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim sqlquer2 As String = "UPDATE Switch SET Serial = '" & swserial.Text & "', Model = '" & swmodel.Text & "',Ports = '" & swport.Text & "', Remarks = '" & swremarks.Text & "', DateChecked = '" & swdate.Text & "', WHERE ID = " & id & ""
Dim sqlcom2 As New OleDb.OleDbCommand
With sqlcom2
.CommandText = sqlquer2
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("UPDATE SUCCESSFUL")
loadListView()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim sqlquer3 As String = "UPDATE Cables SET Type = '" & caserial.Text & "', Remarks = '" & caremarks.Text & "', DateChecked = '" & cadate.Text & "', WHERE ID = " & id & ""
Dim sqlcom3 As New OleDb.OleDbCommand
With sqlcom3
.CommandText = sqlquer3
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("UPDATE SUCCESSFUL")
loadListView()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Try
Dim sqlquer4 As String = "UPDATE Devices SET Type = '" & devtype.Text & "', Model = '" & devmodel.Text & "', Remarks = '" & devremarks.Text & "', DateChecked = '" & devdate.Text & "', WHERE ID = " & id & ""
Dim sqlcom4 As New OleDb.OleDbCommand
With sqlcom4
.CommandText = sqlquer4
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("UPDATE SUCCESSFUL")
loadListView()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Try
Dim sqlquer5 As String = "UPDATE Monitor SET Serial = '" & monser.Text & "', Model = '" & monmod.Text & "',Size = '" & monsize.Text & "', Remarks = '" & monrem.Text & "', DateChecked = '" & mondate.Text & "', WHERE ID = " & id & ""
Dim sqlcom5 As New OleDb.OleDbCommand
With sqlcom5
.CommandText = sqlquer5
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("UPDATE SUCCESSFUL")
loadListView()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Try
Dim sqlquer6 As String = "UPDATE CPU SET Serial = '" & cpser.Text & "', Model = '" & cpmod.Text & "', Remarks = '" & cprem.Text & "', DateChecked = '" & cpdate.Text & "', WHERE ID = " & id & ""
Dim sqlcom6 As New OleDb.OleDbCommand
With sqlcom6
.CommandText = sqlquer6
.Connection = conn
.ExecuteNonQuery()
End With
MsgBox("UPDATE SUCCESSFUL")
loadListView()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
这是应该发生编辑部分的地方。我试着寻找答案,其中没有一个接着工作。我不知道为什么我一直收到“.ExecuteNonQuery()”部分的错误。
答案 0 :(得分:1)
您需要删除“WHERE”子句
之前的最后一个逗号