刘晓强 发表于 2013-7-11 14:56:46

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)里面.但不知上面的语句该怎么修改,请各位帮助.谢谢!

淡写轻描 发表于 2013-7-11 15:07:58

普通浏览复制代码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]
查看完整版本: VBA连接SQL Server数据库, IP地址如何引用单元格上的值?