表单加载
Dim query as String
query = "SELECT proj_name FROM Project"
Dim dt as New Datatable
dt = ExecuteQuery(query) 'ExecuteQuery is where my database is connected. the one that queries
cmbProj.DataSource = dt
我的ExecuteQuery()代码
Dim connectionString As String = "Data Source=jordan;Initial Catalog=PayrollThesis;Integrated Security=True"
Public Function ExecuteQuery(ByVal query As String) As DataTable
Try
Dim Con As New SqlConnection(connectionString)
Dim DA As New SqlDataAdapter(query, Con)
Dim CB As New SqlCommandBuilder(DA)
Dim DT As New DataTable
DA.Fill(DT)
Return DT
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
End Function
希望这已经足够了。 :)