Datagrid - Refresh
-
:confused: Any help would be appreciated. I am trying to design my form to display the data using a Selected Value from a listbox. I set the lbShop.SelectedIndexChanged event to refresh the datagrid when a new value is selected. The variable SShop1 is changed correctly as each item in the listbox is selected, but the datagrid will not refresh using the SQL Select string. What I need is the new SQL Select command to run with the user selected variable, clear the datagrid, and display the data from the new SQL string. Private Sub frmAllOpenbyShop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cnn.Open() reader = dr5.ExecuteReader() While reader.Read() values.Add(reader.Item("Shops").ToString()) End While lbShop.DataSource = values reader.Close() Try 'Attempt to load the dataset. Me.loadDoc() Catch eLoad As System.Exception 'Add your error handling code here. 'Display error message, if any. System.Windows.Forms.MessageBox.Show(eLoad.Message) End Try End Sub ******************************************************************************* Public Sub dadapt1() SShop1 = lbShop.SelectedItem DAdapt.SelectCommand = New SqlCommand DAdapt.SelectCommand.CommandType = CommandType.Text DAdapt.SelectCommand.Connection = cnn1 DAdapt.SelectCommand.CommandText = "Select SystemName, Shop, ActionTaken, TaskNotes, Symptoms, TroubleShooting, Conclusion FROM Workorders WHERE TaskNotes LIKE '" & SShop1 & "' ORDER BY Shop" End Sub ******************************************************************************* Public Sub loadDoc() Me.dadapt1() Try dsSearch2.Clear() DAdapt.Fill(dsSearch2) Catch ex As SqlException End Try grdWorkorders.DataSource = dsSearch2 End Sub ******************************************************************************* Private Sub lbShop_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbShop.SelectedIndexChanged grdWorkorders.Refresh() Me.loadDoc() End Sub LWhite
-
:confused: Any help would be appreciated. I am trying to design my form to display the data using a Selected Value from a listbox. I set the lbShop.SelectedIndexChanged event to refresh the datagrid when a new value is selected. The variable SShop1 is changed correctly as each item in the listbox is selected, but the datagrid will not refresh using the SQL Select string. What I need is the new SQL Select command to run with the user selected variable, clear the datagrid, and display the data from the new SQL string. Private Sub frmAllOpenbyShop_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cnn.Open() reader = dr5.ExecuteReader() While reader.Read() values.Add(reader.Item("Shops").ToString()) End While lbShop.DataSource = values reader.Close() Try 'Attempt to load the dataset. Me.loadDoc() Catch eLoad As System.Exception 'Add your error handling code here. 'Display error message, if any. System.Windows.Forms.MessageBox.Show(eLoad.Message) End Try End Sub ******************************************************************************* Public Sub dadapt1() SShop1 = lbShop.SelectedItem DAdapt.SelectCommand = New SqlCommand DAdapt.SelectCommand.CommandType = CommandType.Text DAdapt.SelectCommand.Connection = cnn1 DAdapt.SelectCommand.CommandText = "Select SystemName, Shop, ActionTaken, TaskNotes, Symptoms, TroubleShooting, Conclusion FROM Workorders WHERE TaskNotes LIKE '" & SShop1 & "' ORDER BY Shop" End Sub ******************************************************************************* Public Sub loadDoc() Me.dadapt1() Try dsSearch2.Clear() DAdapt.Fill(dsSearch2) Catch ex As SqlException End Try grdWorkorders.DataSource = dsSearch2 End Sub ******************************************************************************* Private Sub lbShop_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbShop.SelectedIndexChanged grdWorkorders.Refresh() Me.loadDoc() End Sub LWhite
If you want to do a LIKE query, you need to put the wildcards in, otherwise just use =. This is not production quality code, a SQL injection attack will perform whatever SQL the malicious user wants to run on it. Haev you stepped through to see how the code is being executed ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
If you want to do a LIKE query, you need to put the wildcards in, otherwise just use =. This is not production quality code, a SQL injection attack will perform whatever SQL the malicious user wants to run on it. Haev you stepped through to see how the code is being executed ?
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
Thank you, I replaced the LIKE with = as I didn't need a wildcard search anyway. I will have to look at tightening the code to protect from attack. I stepped through the code and find that if I leave the SShop1 variable = nothing, I get my entire database, as expected, but when I try to set the variable to = a selection from the listbox, I get nothing displayed, just an empty datagrid. This is the line I rem'd out to get a default variable of nothing: SShop1 = lbShop.SelectedItem Thank you for responding to my question. Larry
LWhite