vb.net 怎么样通过窗体输入连接sql数据库
这是我写的一段查询代码Using ShowDataBinding As New DataClasses1DataContext("Data Source=PC2013030515PKF;Initial Catalog=song;Integrated Security=True")
If Not ShowDataBinding.DatabaseExists() Then
MsgBox("显示数据失败,请检查数据库连通!")
Else
Dim SelData = From cust In ShowDataBinding.xm1
If SelData.Any Then
DataGridView1.DataSource = SelData
End If
End If
End Using
怎么样能够把
Using ShowDataBinding As New DataClasses1DataContext("Data Source=PC2013030515PKF;Initial Catalog=song;Integrated Security=True")
这句里的连接字符串Data Source=PC2013030515PKF;Initial Catalog=song;Integrated Security=True
设置为窗体输入。求代码,新人,多多指教。 VB.NET SQL --------------------编程问答-------------------- 用个文本框输入主机名
Dim DSC As String
DSC = Text1.Text
DSC = DSC & ";Initial Catalog=song;Integrated Security=True"
Using ShowDataBinding As New DataClasses1DataContext(DSC)
……
--------------------编程问答-------------------- 如果只是本机运行的话
建议自动获取主机名比较好
Public Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetPcName() As String
Dim compname As String, retval As Long
compname = Space(255)
retval = GetComputerName(compname, 255)
compname = Left(compname, InStr(compname, vbNullChar) - 1)
GetPcName = compname
End Function
Dim DSC As String
DSC = GetPcName & ";Initial Catalog=song;Integrated Security=True"
Using ShowDataBinding As New DataClasses1DataContext(DSC)
……
补充:VB , 网络编程