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. C#
  4. Sql Database LookUp

Sql Database LookUp

Scheduled Pinned Locked Moved C#
databasedebugging
4 Posts 3 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.
  • B Offline
    B Offline
    boiDev
    wrote on last edited by
    #1

    Hi All I have done a Sql database look up. I put the code on the button click event. I want it so that wen i type in something in the text box it will make sure there is text in the texbox before soearching. Becuase at the moment when i debug and click the button it will ust load every thing without men typing in it. Here is my Code //Find Button private void FindButton_Click(object sender, RoutedEventArgs e) { var cmd = new SqlCommand( @"SELECT b.EafGeobldID, b.BuildingName FROM EafGeoZip z inner join EafGeoBld b on z.EafGeoZipID = b.EafGeoZipID WHERE ZIPCode LIKE '%" + tbPostCode.Text + "%'"); var reader = Read(cmd); if (!reader.HasRows) return; while (reader.Read()) { var item = new ItemObject { Key = string.Format("{0}", reader.GetString(1)), ValueOfKey = reader.GetInt64(0).ToString() }; cbBuilding.Items.Add(item); } } //TextBox public void tbPostCode_TextChanged(object sender, TextChangedEventArgs e) { } What do i have to do to accomplish this.. Thank You in advance

    M J 2 Replies Last reply
    0
    • B boiDev

      Hi All I have done a Sql database look up. I put the code on the button click event. I want it so that wen i type in something in the text box it will make sure there is text in the texbox before soearching. Becuase at the moment when i debug and click the button it will ust load every thing without men typing in it. Here is my Code //Find Button private void FindButton_Click(object sender, RoutedEventArgs e) { var cmd = new SqlCommand( @"SELECT b.EafGeobldID, b.BuildingName FROM EafGeoZip z inner join EafGeoBld b on z.EafGeoZipID = b.EafGeoZipID WHERE ZIPCode LIKE '%" + tbPostCode.Text + "%'"); var reader = Read(cmd); if (!reader.HasRows) return; while (reader.Read()) { var item = new ItemObject { Key = string.Format("{0}", reader.GetString(1)), ValueOfKey = reader.GetInt64(0).ToString() }; cbBuilding.Items.Add(item); } } //TextBox public void tbPostCode_TextChanged(object sender, TextChangedEventArgs e) { } What do i have to do to accomplish this.. Thank You in advance

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      X| what a mess lol

      //this will check textbox has text in
      if(string.isnullorempty(textbox1.text))
      {
      //do sql stuff
      }

      use system.data.sqlclient for the sql part

      My opinion is... If someone has already posted an answer, dont post the SAME answer

      1 Reply Last reply
      0
      • B boiDev

        Hi All I have done a Sql database look up. I put the code on the button click event. I want it so that wen i type in something in the text box it will make sure there is text in the texbox before soearching. Becuase at the moment when i debug and click the button it will ust load every thing without men typing in it. Here is my Code //Find Button private void FindButton_Click(object sender, RoutedEventArgs e) { var cmd = new SqlCommand( @"SELECT b.EafGeobldID, b.BuildingName FROM EafGeoZip z inner join EafGeoBld b on z.EafGeoZipID = b.EafGeoZipID WHERE ZIPCode LIKE '%" + tbPostCode.Text + "%'"); var reader = Read(cmd); if (!reader.HasRows) return; while (reader.Read()) { var item = new ItemObject { Key = string.Format("{0}", reader.GetString(1)), ValueOfKey = reader.GetInt64(0).ToString() }; cbBuilding.Items.Add(item); } } //TextBox public void tbPostCode_TextChanged(object sender, TextChangedEventArgs e) { } What do i have to do to accomplish this.. Thank You in advance

        J Offline
        J Offline
        J4amieC
        wrote on last edited by
        #3

        I dare you to type into your textbox %';DELETE FROM EafGeoZip read this: http://www.codeproject.com/KB/database/SqlInjectionAttacks.aspx[^]

        M 1 Reply Last reply
        0
        • J J4amieC

          I dare you to type into your textbox %';DELETE FROM EafGeoZip read this: http://www.codeproject.com/KB/database/SqlInjectionAttacks.aspx[^]

          M Offline
          M Offline
          musefan
          wrote on last edited by
          #4

          Genius!!! why didnt i think of that. If he types that then it will fix both his issues very quickly... maybe....

          My opinion is... If someone has already posted an answer, dont post the SAME answer

          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