gpt4 book ai didi

mysql - 显示多个值(value)成员(member)

转载 作者:行者123 更新时间:2023-11-29 13:52:38 27 4
gpt4 key购买 nike

我使用vb.net。有一个小问题。我从组合框中选择了那个student_id,然后我需要另一个文本框根据所选id更改数据,但问题是值成员只读取一个值成员。

这是我的代码:

    Dim dastudent As New Odbc.OdbcDataAdapter("SELECT * from student ", myconnection)
Dim dsstudent As New DataSet

'Load data about student id into the combo box
dastudent.Fill(dsstudent, "student")
cboID.DataSource = dsstudent.Tables("student")
cboID.DisplayMember = "Student_Id"
cboID.ValueMember = "Student_Name"
cboID.ValueMember = "Student_Tel_No"
cboID.ValueMember = "Student_Address"
cboID.ValueMember = "Mentor_Name"
End Sub

Private Sub cboID_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboID.SelectedIndexChanged
Dim dastudent As New Odbc.OdbcDataAdapter("SELECT * from student WHERE (Student_Id= '" & cboID.Text & "')", myconnection)

txtName.Text = cboID.SelectedValue.ToString()
txtTelNo.Text = cboID.SelectedValue.ToString()
lboAddress.Text = cboID.SelectedValue.ToString()
txtMentor.Text = cboID.SelectedValue.ToString()
End Sub

如何根据数据库中的索引分配值成员。提前致谢。

最佳答案

我强烈建议您开始学习如何使用类,这是一个完美的例子。您可以查询学生并将其存储以供将来使用。

快速回答。这是您需要执行的操作的示例。

    Dim dastudent As New Odbc.OdbcDataAdapter("SELECT * from student ", myconnection)
Dim dsstudent As New DataSet

'Load data about student id into the combo box
dastudent.Fill(dsstudent, "student")
cboID.DataSource = dsstudent.Tables("student")
cboID.DisplayMember = "Student_Id"
cboID.ValueMember = "Student_Id"
End Sub

Private Sub cboID_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboID.SelectedIndexChanged
Dim dastudent As New Odbc.OdbcDataAdapter("SELECT * from student WHERE (Student_Id= '" & cboID.SelectedValue.ToString() & "')", myconnection)

Dim dsstudent As New DataSet

'Load data about student id into the combo box
dastudent.Fill(dsstudent, "student")

txtName.Text = dsstudent.Tables("student").Rows(dsstudent.Tables("student").Columns("Student_Name").Ordinal).ToString()
txtTelNo.Text = dsstudent.Tables("student").Rows(dsstudent.Tables("student").Columns("Student_Tel_No").Ordinal).ToString()
lboAddress.Text = dsstudent.Tables("student").Rows(dsstudent.Tables("student").Columns("Student_Address").Ordinal).ToString()
txtMentor.Text = dsstudent.Tables("student").Rows(dsstudent.Tables("student").Columns("Mentor_Name").Ordinal).ToString()
End Sub

关于mysql - 显示多个值(value)成员(member),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16450867/

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