VBA连接SQL Server数据库, IP地址如何引用单元格上的值?
Dim cnn As ADODB.Connection Dim rs As ADODB.Recordset Dim sql As String, mydata As String, mytable As String mydata = "MYSQL" Set cnn = New ADODB.Connection cnn.ConnectionString = "Provider=SQLOLEDB; User ID=sa;Password=123;Data Source=***.***.***.***" cnn.Open上面的星号为数据库IP地址,填上实际IP后,可以连接上,但因为这个IP是电信的动态IP地址,经常变动,所以想将IP地址放在Sheet1.Cells(1,1)里面.但不知上面的语句该怎么修改,请各位帮助.谢谢! 普通浏览复制代码Dim cnn As ADODB.Connection Dim rs As ADODB.Recordset Dim sql As String, mydata As String, mytable As String Dim ip as String mydata = "MYSQL" ip=sheet1.cells(1,1).text Set cnn = New ADODB.Connection cnn.ConnectionString = "Provider=SQLOLEDB; User ID=sa;Password =123;Data Source=" & ip cnn.Open
页:
[1]