上传数据到SQLServer
我正在做一个macros来上传数据到SQLServer,我想要这个表,每次你运行macros
- 想要使用Recordset添加最后一个添加的行
Sub GetData() Call RecordsetFromSheet(prueba) End Sub
Public Function RecordsetFromSheet(ByVal tableName As String) Dim cn As Object Dim rs As Object Dim strCon As String Dim strSQL, strInput As String Dim cmd As Object
打开连接到SQL Server
Set cn = CreateObject("ADODB.Connection") cn.ConnectionString = OleDbConnectionString("xxxxx", "xxxx", "xx", "xxxxxxx") cn.Open
closures连接
If CBool(cn.State And adStateOpen) = True Then cn.Close Set cn = Nothing End If End Function
函数为StringConnection
Function OleDbConnectionString(ByVal Server As String, ByVal Database As String, _ ByVal UserName As String, ByVal Password As String) As String If UserName = "" Then OleDbConnectionString = "Provider=SQLOLEDB.1;Data Source=" & Server _ & ";Initial Catalog=" & Database _ & ";Integrated Security=SSPI;Persist Security Info=False;" Else OleDbConnectionString = "Provider=SQLOLEDB.1;Data Source=" & Server _ & ";Initial Catalog=" & Database _ & ";User ID=" & UserName & ";Password=" & Password & ";" End If End Function