问题描述
下面是我到目前为止将Table1复制到同一MS Access数据库中的新Table2的VB.Net代码。但是,我收到错误消息,其中包含以下行: dbConFromDatabase.Executenonquery strSQL ,消息为 ExecuteNonQuery不是System.Data.OleDbConnection 的成员。我是VB.Net的新手。为了执行SQL SELECT * INTO ...语句,我需要什么语句?有人可以帮我纠正这个代码,以便它可以运行没有错误?我会永远很棒!
Below is the VB.Net code I have so far to copy Table1 to a new Table2 within the same MS Access database. However, I get the error message with the line that says: dbConFromDatabase.Executenonquery strSQL, and the message is ExecuteNonQuery is not a member of System.Data.OleDbConnection. I am new to VB.Net. What is the statement that I need in order to execute the SQL SELECT * INTO... statement? Can someone help me correct this code so that it will run without an error? I will be eternally greatful!
Module Module1
Private Sub CopyTable(strFromDatabase As String, strTableName As String, strToDatabase As String)
Dim strSQL As String
Dim dbConFromDatabase As OleDb.OleDbConnection
Try
'open connection from database
dbConFromDatabase = New OleDb.OleDbConnection
dbConFromDatabase.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strToDatabase & ";Persist Security Info=False"
dbConFromDatabase.Open()
strSQL = "SELECT * INTO " & strTableName & " FROM " & strTableName & " IN '" & strFromDatabase & "';"
dbConFromDatabase.Executenonquery strSQL
dbConFromDatabase.Close()
dbConFromDatabase = Nothing
Catch ex As Exception
End Try
End Sub
End Module
推荐答案
dbConFromDatabase.Open();
OleDbCommand command = new OleDbCommand(strSQL, dbConFromDatabase);
command.ExecuteNonQuery();
Imports System.Data.OleDb
Module Module1
Private Sub CopyTable(strFromDatabase As String, strTableName As String, strToDatabase As String)
Dim strSQL As String
Dim dbConFromDatabase As OleDb.OleDbConnection
Try
'open connection from database
dbConFromDatabase = New OleDb.OleDbConnection
dbConFromDatabase.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strToDatabase & ";Persist Security Info=False"
dbConFromDatabase.Open()
strSQL = "SELECT * INTO " & strTableName & " FROM " & strTableName & " IN '" & strFromDatabase & "';"
OleDbCommand.Command() = New OleDbCommand(strSQL, dbConFromDatabase)
Command.ExecuteNonQuery()
dbConFromDatabase.Close()
dbConFromDatabase = Nothing
Catch ex As Exception
MsgBox(Err)
End Try
End Sub
End Module
Imports System.Data.OleDb
Module Module1
Private Sub CopyTable(strFromDatabase As String, strTableName As String, strToDatabase As String)
Dim strSQL As String
Dim dbConFromDatabase As OleDb.OleDbConnection
Try
'open connection from database
dbConFromDatabase = New OleDb.OleDbConnection
dbConFromDatabase.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strToDatabase & ";Persist Security Info=False"
dbConFromDatabase.Open()
strSQL = "SELECT * INTO " & strTableName & " FROM " & strTableName & " IN '" & strFromDatabase & "';"
OleDbCommand.Command() = New OleDbCommand(strSQL, dbConFromDatabase)
Command.ExecuteNonQuery()
dbConFromDatabase.Close()
dbConFromDatabase = Nothing
Catch ex As Exception
MsgBox(Err)
End Try
End Sub
End Module
这篇关于SELECT * INTO语句出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!