gpt4 book ai didi

mysql - 来自 MySQL 的 VB.NET ComboBox SelectedIndex

转载 作者:行者123 更新时间:2023-11-29 20:19:28 25 4
gpt4 key购买 nike

所以我已经完成了从数据库 MySQL 到 ComboBox 的显示数据..我正在使用以下代码:

Private Sub Get_Product()
Connection()

Dim command As New MySqlCommand
Dim reader As MySqlDataReader
Dim query As String = "SELECT * FROM product, writer, publisher WHERE product.writer = writer.writer AND product.publisher = publisher.publisher AND code = " & throwCode & " ORDER BY code"

Dim queryWriter As String = "SELECT DISTINCT writer, writer_name FROM writer ORDER BY writer_name"
Dim dataAdapter As New MySqlDataAdapter(queryWriter, conn)
Dim dataSet As New DataSet
dataAdapter.Fill(dataSet, "writer")

Try
command = New MySqlCommand(query, conn)
reader = command.ExecuteReader

While reader.Read
TextBoxISBN.Text = reader("isbn")
TextBoxTitle.Text = reader("title")
TextBoxPage.Text = reader("page")

With (ComboBoxWriter)
.Items.Add("Select")
.DataSource = dataSet.Tables("writer")
.DisplayMember = "writer_name"
.ValueMember = "writer"
.SelectedIndex = 0 **// Give atention to this code**
End With

TextBoxYear.Text = reader("year")
TextBoxCategory.Text = reader("category")
TextBoxCallNumber.Text = reader("call_number")
TextBoxWeight.Text = reader("weight")
TextBoxPurchasePrice.Text = reader("purchase_price")
TextBoxSellingPrice.Text = reader("selling_price")
TextBoxDiscount.Text = reader("discount")
TextBoxDescription.Text = reader("description")
TextBoxTag.Text = reader("tag")

TextBoxPusatPenerbit.Text = reader("pusat_penerbit")
TextBoxMrican.Text = reader("mrican")
TextBoxPaingan.Text = reader("paingan")

If (Not IsDBNull(reader("picture"))) Then
Dim byteImage() As Byte = reader("picture")
Dim tempImage As New System.IO.MemoryStream(byteImage)
PictureBoxPicture.Image = Image.FromStream(tempImage)
End If
End While

conn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

在我的代码中,我给出了一些注释并加粗以向您展示我想要做什么。

所以我在产品中有一个作家代码,在作家中有一个作家代码(作家代码名为作家),我加入表格以显示作家代码中的作家姓名。但在 ComboBox 中,我想显示所有编写器进行编辑,但默认值是编写器的索引,与产品表中的相同。

1

enter image description here

2

enter image description here

如果您看到我的第一张图像的作者名为 Sutarjo Adisusilo,但当我查看它并希望将其用作组合框中的默认值时,该组合框中将 A. Kardiyat Wiharyanto 显示为索引值编号 0..

我需要帮助如何将默认值更改为与图片编号 1 相同

谢谢

最佳答案

我已将此答案更新为更简单的方法。不过,请仔细检查列名称。

ComboBoxWriter.SelectedIndex = ComboBoxWriter.FindStringExact(reader("writer_name"))

关于mysql - 来自 MySQL 的 VB.NET ComboBox SelectedIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39566515/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com