Home > Net >  VB.NET multiple combobox conditions, according to data together with the datagridview query to query
VB.NET multiple combobox conditions, according to data together with the datagridview query to query

Time:04-12

VB.NET multiple combobox conditions, according to the query to the data together with the datagridview why doesn't my point query datagridview display data,

All code:
Public Class Studentclassenquiry
Dim objConn As New MySqlConnection
Dim objComm As New MySqlCommand
Dim DA As New MySqlDataAdapter
Dim DS As New DataSet
'objConn. The ConnectionString=My. Forms. The Login. Conn
Private Sub Studentclassenquiry_Load (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles MyBase. Load
ObjConn. The ConnectionString=My. Forms. The Login. Conn
DS. Tables. The Clear ()
DS. The Clear ()
DA=New MySqlDataAdapter (" select * from camnpus ", objConn)
DA. The Fill (DS, "camnpus")
'ComboBox1. The DataSource=DS. Tables (0)
ComboBox1. DisplayMember="Caname"
ComboBox1. ValueMember="CaId"
ComboBox1. The DataSource=DS. Tables (0)
End Sub

Private Sub ComboBox1_SelectedIndexChanged (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles ComboBox1. SelectedIndexChanged
DS. Tables. The Clear ()
DS. The Clear ()
DA=New MySqlDataAdapter (" select * from building the where CamId='" & amp; ComboBox1. SelectedValue. ToString () & amp; "'", objConn)
DA. The Fill (DS, "building")
ComboBox2. DisplayMember="Bname"
ComboBox2. ValueMember="BId"
ComboBox2. The DataSource=DS. Tables (0)

End Sub
Private Sub ComboBox2_SelectedIndexChanged (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles ComboBox2. SelectedIndexChanged
DS. Tables. The Clear ()
DS. The Clear ()
ObjConn. The Open ()
DA=New MySqlDataAdapter (" select * from classroom where BuiId='" & amp; ComboBox2. SelectedValue. ToString () & amp; "'", objConn)
DA. The Fill (DS, "classroom")
ComboBox3. DisplayMember="Came"
ComboBox3. ValueMember="CId"
ComboBox3. The DataSource=DS. Tables (0)
ObjConn. Close ()
End Sub
Private Sub Button6_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles Button6. Click
ObjConn. The ConnectionString=My. Forms. The Login. Conn
DS. Tables. The Clear ()
DS. The Clear ()
Dim dt As New DataTable
ObjConn. The Open ()
DA=New MySqlDataAdapter (" select CamId as campus to BuId the as the building and every number as the classroom, the Classname as classroom name, UseId as user number, UseBegin as the start time, UseEnd as end time, Userstatus as the user types the from byclassroom where BuId='" & amp; ComboBox2. SelectedValue. ToString () & amp; "' AND every" & amp; ComboBox3. SelectedValue. ToString () & amp; "'", objConn)
DA. The Fill (DS, "byclassroom")
Dt=DS. Tables (" byclassroom ")
ObjConn. Close () 'Close the database
DataGridView1. AutoGenerateColumns=True 'automatically create columns
DataGridView1. The DataSource=dt
End Sub
The End of the Class

CodePudding user response:

To see you this Button6 ComboBox1 ComboBox2, ComboBox3 to gas, unless the tests and assignments, otherwise break earlier this smelly trouble, controls hauled out immediately, otherwise you look back control of a line are meaningless, who knows what is the content,

The code should not be not wrong, if tired went out for a walk, calm down and look at the code, under the careful analysis of the reason, don't show? Or check no results? Or have an error? Along this train of thought, to add a breakpoint to see a detailed operation to variable is somewhere you expect, such as check the SQL statement, whether right, format is not as long as the error is probably true, but there is something wrong with the logic, copying out to the database software to perform, adjusted the SQL statement to see stitching right back then,

Thought so, the code quality is too low, impatient, debugged,
  • Related