Не удается обновить подключенную таблицу
Private Sub UpdateTable(ReportName As String) не выдает ошибку, но и не обновляет таблицу.
Я знаю, что это что-то незначительное, но не могу понять.
Спасибо за любую помощь.
Что я уже пробовал:
Option Compare Text Imports System.Globalization Imports System.IO Imports System.Text Imports Renci Imports Renci.SshNet Imports Renci.SshNet.Sftp Imports System.Data.OleDb Public Class Form1 ' Dim cmdOLEDB As New OleDbCommand Dim cmdInsert As New OleDbCommand Dim cmdUpdate As New OleDbCommand Dim cmdDelete As New OleDbCommand Dim cnnOLEDB As New OleDbConnection Dim dbProvider As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;" Public HomeDir As String = Directory.GetCurrentDirectory & "\" Dim TheDatabase As String = "AddressBook.mdb" Dim dbSource As String = "Data Source = " & HomeDir & TheDatabase & ";Jet OLEDB:System Database=" & HomeDir & "AddressBook.mdw;User ID = End_User;" Private host As String = "" Private port As Integer = 0 Private username As String = "" Private password As String = "" Private remoteDirectory As String = "" Private encryptcode As String = "" Private files As String = "" Dim directoryinfo Dim f Dim sfilename As String Dim strExt As String Dim strQuery As String = "Select * from usysConnect" ' Connect to remote site And download filenames. If extension matches, write to a table. Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try If Not IO.File.Exists(HomeDir & TheDatabase) Then MessageBox.Show("Database not found") Else cnnOLEDB.ConnectionString = dbProvider & dbSource cnnOLEDB.Open() Dim cmd As OleDbCommand = Nothing Dim reader As OleDbDataReader = Nothing cmd = New OleDbCommand("Select * From UsysConnect", cnnOLEDB) reader = cmd.ExecuteReader() While reader.Read() host = IIf(reader.IsDBNull(0), "", reader.GetValue(0)) port = IIf(reader.IsDBNull(1), 0, reader.GetValue(1)) username = IIf(reader.IsDBNull(2), "", reader.GetValue(2)) password = IIf(reader.IsDBNull(3), "", reader.GetValue(3)) encryptcode = IIf(reader.IsDBNull(4), "", reader.GetValue(4)) End While Using sftp As SftpClient = New SftpClient(host, port, username, password) sftp.Connect() directoryinfo = sftp.ListDirectory(remoteDirectory) For Each f In directoryinfo sfilename = (f.Name) strExt = Path.GetExtension(sfilename) If strExt = ".zip" Then UpdateTable(sfilename) End If Next f sftp.Disconnect() End Using End If Catch ex As Exception MsgBox(ex.Message & " - " & ex.Source) End Try If Not IsNothing(cnnOLEDB) Then cnnOLEDB.Close() End If Me.Close() End Sub Private Sub UpdateTable(ReportName As String) Dim Str As String = "" Dim cmd As OleDbCommand = Nothing If Not IO.File.Exists(HomeDir & TheDatabase) Then MessageBox.Show("Database not found") Else Try cmd = New OleDbCommand("Select * From Usysreportname", cnnOLEDB) Str = "UPdate() UsysReportName SET ReportName =" & ReportName cmd.ExecuteNonQuery() Catch ex As Exception MessageBox.Show("Could Not Insert Record!!!") MsgBox(ex.Message & " - " & ex.Source) cnnOLEDB.Close() End Try End If End Sub End Class
T Gorman
Не могли бы вы уточнить? Я пробовал различные коды, чтобы заставить его работать, например
cmd = New OleDbCommand("UPDATE * From Usysreportname", cnnOLEDB)
Str = "UPDATE() UsysReportName SET ReportName =" & ReportName
УМК.Метод executenonquery()
Вы делаете вывод, что я путаю операторы SELECT и UPDATE. Не могли бы вы конкретно процитировать правильный код, пожалуйста?
MadMyche
UPDATE * From Usysreportname
не является допустимым оператором SQL.