0

Hi, i am new on vb.net and MySql, and i have a problem.

My database name is "plant3", i have a table named "itemlist" which has a field named
"itemname", "task", and "status". I want to show the itemname on combobox and when user choice an itemname the program will show all task and status for that item.

Someone please help me..

2
Contributors
2
Replies
11
Views
7 Years
Discussion Span
Last Post by boe_sue
0

you can use displaymember and valuemember proprties of combobox.
For e.g.

---first Open the connection

connection.OPen();
Dim dt as DataTable,sql as string
sql="Select ID,Name from emplayee;"
MysqlDataAdpter Adpter=new MysqlDataAdapter(sql,Connection);
--fill the Datatable with the Data.
Adpter.Fill(dt)

--Now Combo BOx
Combobox1.DataSource=dt;
Combobox1.DispalyMember="ID"
Combobox1.ValueMember="Name"

--When you run the programm. combobox display the name of employee and when you select any name then you can takes it value as a Index
0

i get this error "data isnot show"
this is my code:
--------------------------------------------------------------------------------
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

Dim itemname As String = ComboBox1.SelectedText


Dim conn As MySqlConnection
Dim reader As MySqlDataReader = Nothing
Dim cmd As New MySqlCommand

conn = New MySqlConnection
conn.ConnectionString = "server=localhost; user id=root;password=; database=plant3"
cmd.Connection = conn
cmd.CommandText = "SELECT itemname, task, status FROM itemlist where itemname=@itemname"
cmd.Parameters.Add("@itemname", MySqlDbType.VarChar).Value = itemname
conn.Open()

Try
reader = cmd.ExecuteReader()
If reader.Read() Then

MessageBox.Show("data is show")
TextBox1.Text = reader.GetString(0)
TextBox2.Text = reader.GetString(1)
TextBox3.Text = reader.GetString(2)
End If
Catch ex As Exception
MessageBox.Show("failed to populate database list : " + ex.Message)
Finally
If Not reader Is Nothing Then reader.Close()
MessageBox.Show("data isnot show")
End Try
End Sub

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.