Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Datagrid - Refresh

Datagrid - Refresh

Scheduled Pinned Locked Moved Visual Basic
helpdatabasedesign
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Larry White
    wrote on last edited by
    #1

    :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

    C 1 Reply Last reply
    0
    • L Larry White

      :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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      L 1 Reply Last reply
      0
      • C Christian Graus

        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

        L Offline
        L Offline
        Larry White
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups