我的目标是从我的数据库中获取所有表的名称并将其放在我的ComboBox上。多年来我没有使用过vb.net,现在我正在把一些东西弄脏,但我需要帮助,因为我没有出来。这是我的代码:
Imports MySql.Data.MySqlClient
Public Class DataIn
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As New DataTable
Dim SQL As String
Dim MysqlConn As MySqlConnection
Private Sub DataIn_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MysqlConn = New MySqlConnection()
'Connection String
MysqlConn.ConnectionString = "server=localhost;" _
& "user id=root;" _
& "password=123456789;" _
& "database=calendario"
Try
MysqlConn.Open()
SQL = "SELECT name FROM calendario.tables"
myCommand.CommandText = SQL
myAdapter.SelectCommand = myCommand
myAdapter.Fill(myData)
ComboBox1.Items = myData
Catch myerror As MySqlException
MessageBox.Show("Connection failed: " & myerror.Message)
Finally
MysqlConn.Close()
MysqlConn.Dispose()
End Try
End Sub
End Class
我收到了这条消息:
表'calendario.tables'不存在
我做错了什么?
另外,我想知道如何加密ConnectionString
中硬编码的连接详细信息,因为将来必须将此应用程序分发给我的客户。
答案 0 :(得分:2)
使用查询
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA='dbName'
或
USE YOURDBNAME
GO
SELECT *
FROM sys.Tables
GO
并将ComboBox1.Items = myData
更改为
For intcount=0 to mydata.rows.count-1
comboBox1.Items.Add(mydata.rows(intcount).item(0))
Next
希望有所帮助..
答案 1 :(得分:0)
mysql查询,
class ProductSize < ActiveRecord::Base
belongs_to :user
belongs_to :size
validates :quantity, presence: true
end