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. How to Search a datagrid in SQL, VB.net

How to Search a datagrid in SQL, VB.net

Scheduled Pinned Locked Moved Visual Basic
helpdatabasecsharpsecurity
2 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.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    hi All the Following code reside on my Search Button.i want to search the results in datagrid(dataset),using the input from a textbox. and return the results if found. am usng SQl. here is the code i tried write , please help me fix this .

    'Open Database Connection
    Dim strconnection As String = "workstation id=5875-049;packet size=4096;user id=***; Password=******;data source=S*******;persist security info=False;initial catalog=Tshwane_Valuations"
    Dim cn As SqlConnection = New SqlConnection(strconnection)
    cn.Open()

        'set up data adapter 
        Dim strSql As String = \_
        "select Actual\_Extent,Attrib\_code,Lis\_key,Func\_key,Density," \_
          & "New\_Net\_Usable\_Extent,New\_Total\_Land\_Factor,New\_AdJ\_Extent\_1,New\_Points\_1," \_
          & "New\_ADJ\_Extent\_2, New\_Points\_2, LS\_Prediction, LS\_Confidence,LS\_TYPE from Property\_Mass "
        Dim da As SqlDataAdapter = New SqlDataAdapter(strSql, cn)
    
        'load Dataset
        Dim ds As DataSet = New DataSet
        da.Fill(ds, "Property\_Summary")
    
        'Set up a new Data adapter Object
        strSql = "select Property\_Mass.Actual\_Extent,Property\_Mass.Attrib\_code,Property\_Mass.Lis\_key,Property\_Mass.Func\_key,Property\_Mass.Density," \_
       & " Property\_Mass.New\_Net\_Usable\_Extent,Property\_Mass.New\_Total\_Land\_Factor,Property\_Mass.New\_AdJ\_Extent\_1, Property\_Mass.New\_Points\_1," \_
       & " Property\_Mass.New\_ADJ\_Extent\_2, Property\_Mass.New\_Points\_2, Property\_Mass.LS\_Prediction, Property\_Mass.LS\_Confidence, Property\_Mass.LS\_TYPE," \_
       & " Property\_Summary.Purchase\_Date, Property\_Summary.Purchase\_Price" \_
        & " from Property\_Mass, Property\_Summary" \_
        & "where Substring(Lis\_key,1,4)= ?"
    
        da.SelectCommand.Parameters("Lis\_key").Value = txtliskeysearch.Text
        da.Fill(ds)
        If ds.Tables("Property\_Mass").Rows.Count = 0 Then
            MessageBox.Show("Township not Found")
        End If
    
    End Sub
    

    When i run this code it gives me an Error

    An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll

    Additional information: An SqlParameter with ParameterName 'Lis_key' is not contained by this SqlParameterCollection.

    And points to the Following line

    da.SelectCommand.Parameters("Lis_key").Value = txtliskeysearch.Text

    Help Thanks Thanks

    Vuyiswa Maseko

    P 1 Reply Last reply
    0
    • V Vimalsoft Pty Ltd

      hi All the Following code reside on my Search Button.i want to search the results in datagrid(dataset),using the input from a textbox. and return the results if found. am usng SQl. here is the code i tried write , please help me fix this .

      'Open Database Connection
      Dim strconnection As String = "workstation id=5875-049;packet size=4096;user id=***; Password=******;data source=S*******;persist security info=False;initial catalog=Tshwane_Valuations"
      Dim cn As SqlConnection = New SqlConnection(strconnection)
      cn.Open()

          'set up data adapter 
          Dim strSql As String = \_
          "select Actual\_Extent,Attrib\_code,Lis\_key,Func\_key,Density," \_
            & "New\_Net\_Usable\_Extent,New\_Total\_Land\_Factor,New\_AdJ\_Extent\_1,New\_Points\_1," \_
            & "New\_ADJ\_Extent\_2, New\_Points\_2, LS\_Prediction, LS\_Confidence,LS\_TYPE from Property\_Mass "
          Dim da As SqlDataAdapter = New SqlDataAdapter(strSql, cn)
      
          'load Dataset
          Dim ds As DataSet = New DataSet
          da.Fill(ds, "Property\_Summary")
      
          'Set up a new Data adapter Object
          strSql = "select Property\_Mass.Actual\_Extent,Property\_Mass.Attrib\_code,Property\_Mass.Lis\_key,Property\_Mass.Func\_key,Property\_Mass.Density," \_
         & " Property\_Mass.New\_Net\_Usable\_Extent,Property\_Mass.New\_Total\_Land\_Factor,Property\_Mass.New\_AdJ\_Extent\_1, Property\_Mass.New\_Points\_1," \_
         & " Property\_Mass.New\_ADJ\_Extent\_2, Property\_Mass.New\_Points\_2, Property\_Mass.LS\_Prediction, Property\_Mass.LS\_Confidence, Property\_Mass.LS\_TYPE," \_
         & " Property\_Summary.Purchase\_Date, Property\_Summary.Purchase\_Price" \_
          & " from Property\_Mass, Property\_Summary" \_
          & "where Substring(Lis\_key,1,4)= ?"
      
          da.SelectCommand.Parameters("Lis\_key").Value = txtliskeysearch.Text
          da.Fill(ds)
          If ds.Tables("Property\_Mass").Rows.Count = 0 Then
              MessageBox.Show("Township not Found")
          End If
      
      End Sub
      

      When i run this code it gives me an Error

      An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll

      Additional information: An SqlParameter with ParameterName 'Lis_key' is not contained by this SqlParameterCollection.

      And points to the Following line

      da.SelectCommand.Parameters("Lis_key").Value = txtliskeysearch.Text

      Help Thanks Thanks

      Vuyiswa Maseko

      P Offline
      P Offline
      penguin5000
      wrote on last edited by
      #2

      This might help .... http://www.vbforums.com/showthread.php?t=479407[^]

      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