不可能每个窗体的连接路径都要改吧!
在Module1.vb里的:
Imports System.Data.SqlClient
Module Module1
Public ConnString As String = "Data Source=.;Initial Catalog=test;User ID=sa"
Function CreateDataSetaa(ByVal strSQL As String, ByVal TableName As String) As DataSet
Dim objCmd As New SqlDataAdapter(strSQL, ConnString)
Dim DS As New DataSet
objCmd.Fill(DS, TableName)
CreateDataSetaa = DS
End Function
End Module
在Form1.vb里的:
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strSql As String = "select * from aaa"
DataGrid1.DataSource = CreateDataSetaa(strSql, "aaa")
Me.DataGrid1.DataMember = "aaa"
End Sub
End Class
但我很想知道 single 你的那种写法!