我有以下代码:
Using conn = New SqlConnection(connStr)
Dim sql = "SELECT [CATEGORIA], [AREA] FROM [CATEGORIAS] WHERE ([AREA] = @AREA)"
Dim sqlCmd = New SqlCommand(sql, conn)
sqlCmd.Parameters.AddWithValue("@AREA", CStr(PublicLogin.Area))
conn.Open()
Dim ds As New DataSet
Dim da As New SqlDataAdapter(sql, conn)
da.Fill(ds, "CATEGORIAS")
With cboCat
.DataSource = ds.Tables("CATEGORIAS")
.DisplayMember = "CATEGORIAS_AREA"
.ValueMember = "CATEGORIAS_AREA"
.SelectedIndex = 0
End With
End Using
它理论上应该填充组合框吗?它没有。它不会给我任何错误或任何东西;组合框只是空着放在那里。我很确定查询运行良好并且它获取了正确的信息,但组合框没有填满。如果我取出 where 查询,它会用“System.Data.Row ...”填充 CB
更新:工作代码以防有人需要;
Using conn = New SqlConnection(connStr)
Dim sql = "SELECT [CATEGORIA], [AREA] FROM [CATEGORIAS] WHERE ([AREA] = @AREA)"
Dim sqlCmd = New SqlCommand(sql, conn)
sqlCmd.Parameters.AddWithValue("@AREA", CStr(PublicLogin.Area))
conn.Open()
Dim ds As New DataSet
Dim da As New SqlDataAdapter(sqlCmd)
da.Fill(ds, "CATEGORIAS")
With cboCat
.DataSource = ds.Tables("CATEGORIAS")
.DisplayMember = "CATEGORIA"
.ValueMember = "CATEGORIA"
.SelectedIndex = 0
End With
End Using