在文本框VB.net访问中显示数据库中的数据 [英] Displaying Data from Database in Textboxes VB.net Access
本文介绍了在文本框VB.net访问中显示数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在尝试在与组合框文本匹配的文本框中显示数据库中的数据,但是不成功。所有文本框显示为0
这是我已有的代码。
Hello, I am trying to display data from my database in textboxes that matches the text of the combo box however, have been unsuccessful. All the textboxes display are 0's
Here is the code I already have.
Private Sub ComboBox42_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox42.SelectedIndexChanged
dataFile = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Simon\Documents\Visual Studio 2010\Projects\UWOShipTool\UWOShipTool\Ship.mdb"
connString = dataFile
myConnection.ConnectionString = connString
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Ships] WHERE [Name] = '" & ComboBox42.Text & "'", myConnection)
myConnection.Open()
Dim dr As OleDbDataReader = cmd.ExecuteReader
While dr.Read
Found = True
Name = dr("Name")
Dura = dr("Dura")
Vertical = dr("Vertical")
Horizontal = dr("Horizontal")
Row = dr("Row")
Turn = dr("Turn")
Wave = dr("Wave")
Armor = dr("Armor")
Cabin = dr("Cabin")
CannonChambers = dr("Cannon Chambers")
Cargo = dr("Cargo")
End While
TextBox1.Text = Dura
TextBox2.Text = Vertical
TextBox3.Text = Horizontal
TextBox4.Text = Row
TextBox5.Text = Turn
TextBox6.Text = Wave
TextBox7.Text = Armor
TextBox8.Text = Cabin
TextBox9.Text = CannonChambers
TextBox10.Text = Cargo
TextBox11.Text = Adv
TextBox12.Text = Trade
TextBox13.Text = Battle
myConnection.Close()
提前致谢。 :)
Thanks in advance. :)
推荐答案
我认为你必须尝试以下方法:
I think you have to try the following:
Dim DB_Adapter As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM [Ships] WHERE [Name] = '" & ComboBox42.Text & "'", myConnection)
Dim dt As DataTable
DB_Adapter.Fill(dt)
For Each dr As DataRow In dt.Rows
' Here what you want to do with the info stored in the "dr" datarow from the select statement of your data base.
Next
这篇关于在文本框VB.net访问中显示数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文