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. Help reading data

Help reading data

Scheduled Pinned Locked Moved C#
databasecsharpsysadminhelptutorial
4 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.
  • F Offline
    F Offline
    falles01
    wrote on last edited by
    #1

    Can anyopne please tell me whyn this isn't reading data from the database? I'm trying to save multiple entries to the database based on checkedlist box selections. I really need my code proofread. Can someone please tell me in code example what I'm doing wrong? Malcolm is hopefully going to help me but since I'm desperate I am trying to get the quickest help possible and not sure if he'll get back to me in time.I've been trying this for a week by the way. It's for ado.net. SqlConnection adoConn = new SqlConnection("server = ADMMSAS7;database=Dev_RST;Trusted_Connection=yes"); adoConn.Open(); string sql = "select ProgLanguagesDatabase from TechnicalSkills"; SqlCommand adoCmd = new SqlCommand(sql, adoConn); SqlDataReader adoDR = adoCmd.ExecuteReader(); string TechnicalSkills = (string)adoDR["ProgLanguagesDatabase"]; int TechnicalSkillsID = (int)adoDR["TechnicalSkillsID"]; if (adoDR.HasRows) { while (adoDR.Read()) { if (techSkillsCheckListBox2.CheckedItems.Count != 0) { for (int x = 0; x <= techSkillsCheckListBox2.CheckedItems.Count - 1; x++) { if (techSkillsCheckListBox2.CheckedItems[x].Equals(TechnicalSkills)) { sql = "Insert into EmpSkills(EmployeeID,TechnicalSkillsID) values ('" + this.EmployeeID + "','" + techSkillsCheckListBox2.CheckedItems.ToString() + "')"; Sianny aka Sharny

    P 1 Reply Last reply
    0
    • F falles01

      Can anyopne please tell me whyn this isn't reading data from the database? I'm trying to save multiple entries to the database based on checkedlist box selections. I really need my code proofread. Can someone please tell me in code example what I'm doing wrong? Malcolm is hopefully going to help me but since I'm desperate I am trying to get the quickest help possible and not sure if he'll get back to me in time.I've been trying this for a week by the way. It's for ado.net. SqlConnection adoConn = new SqlConnection("server = ADMMSAS7;database=Dev_RST;Trusted_Connection=yes"); adoConn.Open(); string sql = "select ProgLanguagesDatabase from TechnicalSkills"; SqlCommand adoCmd = new SqlCommand(sql, adoConn); SqlDataReader adoDR = adoCmd.ExecuteReader(); string TechnicalSkills = (string)adoDR["ProgLanguagesDatabase"]; int TechnicalSkillsID = (int)adoDR["TechnicalSkillsID"]; if (adoDR.HasRows) { while (adoDR.Read()) { if (techSkillsCheckListBox2.CheckedItems.Count != 0) { for (int x = 0; x <= techSkillsCheckListBox2.CheckedItems.Count - 1; x++) { if (techSkillsCheckListBox2.CheckedItems[x].Equals(TechnicalSkills)) { sql = "Insert into EmpSkills(EmployeeID,TechnicalSkillsID) values ('" + this.EmployeeID + "','" + techSkillsCheckListBox2.CheckedItems.ToString() + "')"; Sianny aka Sharny

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      falles01 wrote:

      sql = "Insert into EmpSkills(EmployeeID,TechnicalSkillsID) values ('" + this.EmployeeID + "','" + techSkillsCheckListBox2.CheckedItems.ToString() + "')";

      At first glance, this is vulnerable to a SQL Injection attack (not why it isn't reading from the database, though).

      "Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus

      F 1 Reply Last reply
      0
      • P Paul Conrad

        falles01 wrote:

        sql = "Insert into EmpSkills(EmployeeID,TechnicalSkillsID) values ('" + this.EmployeeID + "','" + techSkillsCheckListBox2.CheckedItems.ToString() + "')";

        At first glance, this is vulnerable to a SQL Injection attack (not why it isn't reading from the database, though).

        "Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus

        F Offline
        F Offline
        falles01
        wrote on last edited by
        #3

        So do you know how to insert multiple values from a checkedlistbox selection?

        P 1 Reply Last reply
        0
        • F falles01

          So do you know how to insert multiple values from a checkedlistbox selection?

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          What I meant by my post was that the way you are concatenating strings together into a sql statement is very bad practice. Read this very useful article http://www.codeproject.com/cs/database/SqlInjectionAttacks.asp[^] by Colin Mackay. As far as inserting multiple values from a checklistbox selection, techSkillsCheckListBox2.CheckedItems.ToString() is suspect. Isn't there supposed to be an Items collection that you can pull the actual data value from? I am not a 100% but look for something like that.

          "Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus

          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