I am So stumped on this..maybe even more stumped than i was when i getting help just accessing the DB file lol
ok here's what i am trying to do start to finish..search the DB for something,Show whatever it finds in a listview, edit a line and save it back to the DB file..
the search part is solved, i can find whatever i need to find and toss the info into the listview..the editing and saving is where I'm banging my head
I thought i could use the update code from the previous Post on this but it isn't working out for me for some reason :-)
ok here's what i am trying to do start to finish..search the DB for something,Show whatever it finds in a listview, edit a line and save it back to the DB file..
the search part is solved, i can find whatever i need to find and toss the info into the listview..the editing and saving is where I'm banging my head
I thought i could use the update code from the previous Post on this but it isn't working out for me for some reason :-)
Code:
Imports System.IO
Imports System.Data.OleDb
Public Class DBEditor
Dim App_Path As String = New FileInfo(Application.ExecutablePath).DirectoryName
Dim UpdateCommand As New OleDbCommand
Public FileName As String
Dim CurrentIndex = Form1.ListView1.FocusedItem.Index
Dim EditItem = Form1.ListView1.Items(CurrentIndex)
Public ConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & App_Path & "\RefLib.accdb"
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With EditItem
txtModel.Text = EditItem.Text
txtDocument.Text = .SubItems(1).Text
txtDescription.Text = .SubItems(2).Text
txtByteSize.Text = .SubItems(3).Text
txtFileSize.Text = .SubItems(4).Text
txtStatus.Text = .SubItems(5).Text
txtLocation.Text = .SubItems(6).Text
txtCrc32.Text = .SubItems(7).Text
txtFileName.Text = .SubItems(8).Text
txtSite.Text = .SubItems(9).Text
End With
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim SelectStateMent As String = "SELECT FileName FROM AssistDB WHERE FileName = " & txtFileName.Text
Dim UpdateStatement = "UPDATE AssistDB SET Model = @Model, Document = @Document, Description = @Description, " & _
"ByteSize = @ByteSize, FileSize = @FileSize, Status = @Status, Location = @Location, Crc32 = @Crc32, " & _
"FileName = @FileName, Site = @Site WHERE FileName = @FileName"
Dim InsertStatement = "INSERT INTO AssistDB " & _
"(Model, Document, Description, ByteSize,FileSize, Status, Location, Crc32, FileName,Site) " & _
"VALUES (Model, Document, Description, ByteSize, FileSize, Status, Location, Crc32, FileName, Site)"
Using Connection As New OleDbConnection(ConnectionString), Adapter As New OleDbDataAdapter(SelectStateMent, Connection), _
InsertCommand As New OleDbCommand(InsertStatement, Connection), UpdateCommand As New OleDbCommand(UpdateStatement, Connection)
UpdateCommand.Parameters.AddWithValue("@Model", txtModel.Text)
UpdateCommand.Parameters.AddWithValue("@Document", txtDocument.Text)
UpdateCommand.Parameters.AddWithValue("@Description", txtDescription.Text)
UpdateCommand.Parameters.AddWithValue("@ByteSize", txtByteSize.Text)
UpdateCommand.Parameters.AddWithValue("@FileSize", txtFileSize.Text)
UpdateCommand.Parameters.AddWithValue("@Status", txtStatus.Text)
UpdateCommand.Parameters.AddWithValue("@Location", txtLocation.Text)
UpdateCommand.Parameters.AddWithValue("@Crc32", txtCrc32.Text)
UpdateCommand.Parameters.AddWithValue("@FileName", txtFileName.Text)
UpdateCommand.Parameters.AddWithValue("@Site", txtSite.Text)
Adapter.UpdateCommand = UpdateCommand
End Using
End Sub
End Class