vb.net 怎么样通过窗体输入连接sql数据库

meng208 2013-06-08 01:18:18
这是我写的一段查询代码
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
设置为窗体输入。求代码,新人,多多指教。
...全文
103 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
SongPixy 2013-06-09
  • 打赏
  • 举报
回复
如果只是本机运行的话 建议自动获取主机名比较好 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) ……
SongPixy 2013-06-09
  • 打赏
  • 举报
回复
用个文本框输入主机名 Dim DSC As String DSC = Text1.Text DSC = DSC & ";Initial Catalog=song;Integrated Security=True" Using ShowDataBinding As New DataClasses1DataContext(DSC) ……

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧