我是mysql和vb.net的新手并且有这个查询:
select `db_employee`.`firstName` as `firstName`, `db_employee`.`lastName` as `lastName`,
`tbl_employment`.`position` as `position`
from (`db_employee` `db_employee`
inner join `tbl_employment` `tbl_employment` on (`tbl_employment`.`ctrlID` = `db_employee`.`ctrlID`))
where (`tbl_employment`.`companyName` like 'MES%')
我想转换它在这里使用:
Dim MySqlConn = New MySqlConnection
MySqlConn.ConnectionString = connStr
Dim SDA As New MySqlDataAdapter
Dim dbdataset As New DataTable
Dim bsource As New BindingSource
MySqlConn.Open()
Dim query As String
query = ?
答案 0 :(得分:0)
你可以使用下面的代码来显示数据...我希望这就是你想要的......:)
Dim cn As SqlConn= New SqlConn("Connecting String")
Dim cmd As sqlCommand
Dim dr As sqlDataReader
cn.open()
cmd = New sqlCommand("select * from table or your query, cn)
dr = cmd.ExecuteReader()
dr.Read()
textbox1.Text = dr(1).ToString()
cn.close()
答案 1 :(得分:0)
您可以使用您正在使用的MySQL提供商执行此类操作。这将创建您的连接,命令和数据读取器并正确关闭和处理所有内容。如果需要DataTable实例,可以从DataReader加载它。
Using conn As New MySql.Data.MySqlClient.MySqlConnection("YourConnectionString")
conn.Open()
Using cmd As MySql.Data.MySqlClient.MySqlCommand = conn.CreateCommand
cmd.CommandText = "select db_employee.firstName as firstName, " & _
"db_employee.lastName as lastName, " & _
"tbl_employment.position as position " & _
"from db_employee db_employee " & _
"inner join tbl_employment tbl_employment on tbl_employment.ctrlID = db_employee.ctrlID " & _
"where tbl_employment.companyName like 'MES%' "
' Get a data reader that you can loop over or load a data table with
Dim dr As MySql.Data.MySqlClient.MySqlDataReader = cmd.ExecuteReader
' How to read with a DataReader
While dr.Read
' Do something with this
Dim lastName As String = dr("lastName")
End While
End Using
conn.Close()
End Using