我试图用SQL我认为我的问题是处理数据表形式的数据。 7 R% l" M: D- F8 ?! i Dim sql As String Dim sqlquery As String Dim ConnectionString As String ConnectionString = "Data Source=(local);Initial Catalog=Controlersist Security Info=True;User ID=userassword=pass" sqlquery = "Select dbName from Databases" Using connection As SqlConnection = New SqlConnection(ConnectionString) connection.Open() Using conn As SqlCommand = New SqlCommand(sqlquery,conn) Dim rs As SqlDataReader = comm.ExecuteReader Dim dt As DataTable = New DataTable dt.Load(cmboxDatabaseName) End Using 'comm End Using 'conn当我操作程序时,我只是盯着一个悲伤的空组合框。" k- c& h3 T0 L
) k% p( P% ^8 M! k; ]( G: W. x. Q 解决方案: + d+ S, N8 k, I: t ?7 U
几乎正确,但你需要使用它DataReader加载数据表。8 M! T) I$ f) l& h9 F
然后将数据表与组合的数据源相关联 * L" m# v2 u" b: L% SUsing connection As SqlConnection = New SqlConnection(ConnectionString) connection.Open() Using comm As SqlCommand = New SqlCommand(sqlquery,connection) Dim rs As SqlDataReader = comm.ExecuteReader Dim dt As DataTable = New DataTable dt.Load(rs) as an example set the ValueMember and DisplayMember' to two columns of the returned table cmboxDatabaseName.ValueMember = "IDCustomer" cmboxDatabaseName.DisplayMember = "Name" cmboxDatabaseName.DataSource = dt End Using 'commEnd Using 'conn另外,你可以comboboxValueMember属性设置为将用作将来处理键DisplayMember列的名称,属性设置为用户选择的列的文本