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. dataadapter fill question

dataadapter fill question

Scheduled Pinned Locked Moved C#
helpquestioncssdatabasedata-structures
5 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.
  • T Offline
    T Offline
    theStorminMormon
    wrote on last edited by
    #1

    I have a table. When you select a plan from a listbox and click 'select plan', the program nicely goes out to the database, fetches the plan, and sticks it in a datagrid. This is the code: this.sqlSelectCommand1.CommandText += " WHERE PlanID = '" + PlanIDs[this.clstbxPlans.SelectedIndex].ToString() + "'"; this.sqlDataAdapter.Fill(dataSet2); this.dgClaimsExperience.DataSource = this.dataSet2.tblData; So I'm using data adapter, data connection and data set that I generated via the vs2003 GUI. Anyway it works just fine with two problems. If, after loading one plan, the user selects a different plan and clicks "select plan", I want the new plan to get loaded into the data grid and replace the old one. That's what the "WHERE Plan ID..." part of the code does. It uses the list box and an array of PlanIDs to specify which plan data I wanted loaded. But when I actually try to change plans this way I get an error: An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional information: System error. What gives? My second (more minor) problem is that when the data is loaded into the datagrid, it's too large too fit. This is OK, the data grid has scroll bars. But the problem is that the scroll bars are disabled by default for some reason. I can navigate around easily enough by just plopping my cursor in the data table and manually moving the cursor around the arrow keys - but what do I need to do to get the scroll bars to work like they should? I appreciate the help. This project is killing me. -stormin The ends can never justify the means. It is the means that determine the ends.

    W 1 Reply Last reply
    0
    • T theStorminMormon

      I have a table. When you select a plan from a listbox and click 'select plan', the program nicely goes out to the database, fetches the plan, and sticks it in a datagrid. This is the code: this.sqlSelectCommand1.CommandText += " WHERE PlanID = '" + PlanIDs[this.clstbxPlans.SelectedIndex].ToString() + "'"; this.sqlDataAdapter.Fill(dataSet2); this.dgClaimsExperience.DataSource = this.dataSet2.tblData; So I'm using data adapter, data connection and data set that I generated via the vs2003 GUI. Anyway it works just fine with two problems. If, after loading one plan, the user selects a different plan and clicks "select plan", I want the new plan to get loaded into the data grid and replace the old one. That's what the "WHERE Plan ID..." part of the code does. It uses the list box and an array of PlanIDs to specify which plan data I wanted loaded. But when I actually try to change plans this way I get an error: An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional information: System error. What gives? My second (more minor) problem is that when the data is loaded into the datagrid, it's too large too fit. This is OK, the data grid has scroll bars. But the problem is that the scroll bars are disabled by default for some reason. I can navigate around easily enough by just plopping my cursor in the data table and manually moving the cursor around the arrow keys - but what do I need to do to get the scroll bars to work like they should? I appreciate the help. This project is killing me. -stormin The ends can never justify the means. It is the means that determine the ends.

      W Offline
      W Offline
      Wjousts
      wrote on last edited by
      #2

      Have you checked (by stepping through the code) what the SQL statement being generated is? Are you sure that the ToString method is actually returning a numeric string and not something else (like the type name). Stop the code right before the DataAdapter.Fill and check that the CommandText is actually what you think it is. theStorminMormon wrote: Additional information: System error. Don't you just love how helpful that additional information is?

      T 1 Reply Last reply
      0
      • W Wjousts

        Have you checked (by stepping through the code) what the SQL statement being generated is? Are you sure that the ToString method is actually returning a numeric string and not something else (like the type name). Stop the code right before the DataAdapter.Fill and check that the CommandText is actually what you think it is. theStorminMormon wrote: Additional information: System error. Don't you just love how helpful that additional information is?

        T Offline
        T Offline
        theStorminMormon
        wrote on last edited by
        #3

        Now is as good a time as any to admit my stunning ignorance of how to debug. I know you can step through code using F11, but my code is interactive. It has buttons. So when I try to step through with F11 I just get to the point where the main form pops up. Then if I hit a button, I can't get the F11-step through to start working again. So, if you let me know how to step through code I'll be grateful and I'll try that out to see exactly what's going on. But, just to clarify, there's theoretically nothing wrong with calling a dataadpater to fill a datatable in a dataset more than once? Wjousts wrote: theStorminMormon wrote: Additional information: System error. Don't you just love how helpful that additional information is? Yeah - go to love those specific error messages. They're live savers. Thanks for the help. The ends can never justify the means. It is the means that determine the ends.

        W 1 Reply Last reply
        0
        • T theStorminMormon

          Now is as good a time as any to admit my stunning ignorance of how to debug. I know you can step through code using F11, but my code is interactive. It has buttons. So when I try to step through with F11 I just get to the point where the main form pops up. Then if I hit a button, I can't get the F11-step through to start working again. So, if you let me know how to step through code I'll be grateful and I'll try that out to see exactly what's going on. But, just to clarify, there's theoretically nothing wrong with calling a dataadpater to fill a datatable in a dataset more than once? Wjousts wrote: theStorminMormon wrote: Additional information: System error. Don't you just love how helpful that additional information is? Yeah - go to love those specific error messages. They're live savers. Thanks for the help. The ends can never justify the means. It is the means that determine the ends.

          W Offline
          W Offline
          Wjousts
          wrote on last edited by
          #4

          Using Visual Studio the best way to debug code associated with an event is to set a breakpoint. You set a break point by clicking in the little gray bar to the left of the line of code you want to stop on, a small red circle will appear (click on it again to clear it when you no longer need it). For your situation you could put it right next to the line for the button click event. What happens is when the program reaches that line it will throw you back into debug mode and set you step through with F10 or F11 (note this only works if you're building the debug configuration and not the release one). Once you've stopped execution you can step through and use the watch windows to see the values of variables or use the command window to quickly type code to execute, for example myDataAdapter.SelectCommand.CommandText in the command window should show you what the command text actually is (assuming myDataAdapter is in scope). Hope this helps. You'll learn to love breakpoints!! [Edit: forgot to mention] In answer to your other question, no there is nothing theoretically wrong with using a DataAdapter twice (or more) to fill a table (even the same table). Now whether it's the most efficient way to do things is another question that depends greatly on your setup. -- modified at 16:12 Wednesday 12th October, 2005

          T 1 Reply Last reply
          0
          • W Wjousts

            Using Visual Studio the best way to debug code associated with an event is to set a breakpoint. You set a break point by clicking in the little gray bar to the left of the line of code you want to stop on, a small red circle will appear (click on it again to clear it when you no longer need it). For your situation you could put it right next to the line for the button click event. What happens is when the program reaches that line it will throw you back into debug mode and set you step through with F10 or F11 (note this only works if you're building the debug configuration and not the release one). Once you've stopped execution you can step through and use the watch windows to see the values of variables or use the command window to quickly type code to execute, for example myDataAdapter.SelectCommand.CommandText in the command window should show you what the command text actually is (assuming myDataAdapter is in scope). Hope this helps. You'll learn to love breakpoints!! [Edit: forgot to mention] In answer to your other question, no there is nothing theoretically wrong with using a DataAdapter twice (or more) to fill a table (even the same table). Now whether it's the most efficient way to do things is another question that depends greatly on your setup. -- modified at 16:12 Wednesday 12th October, 2005

            T Offline
            T Offline
            theStorminMormon
            wrote on last edited by
            #5

            Well, your tips on debugging were good, and I'm sure they will come in handy a lot in the future, but my central question is still a mystery to me. As far as I can tell the code is idential the first time it goes through and the second time. Here's the code again: this.sqlDataAdapter.Fill(dataSet2.tblData); this.dgClaimsExperience.DataSource = this.dataSet2.tblData; this.tabctrlTabControl.Enabled = true; It's crashing on the first line when it goes through the second time. The only other difference is that the CommandText of the sql command gets edited a little bit (so that it's drawing a different set of data from the database the second time around). Any ideas how to work around this? -stormin The ends can never justify the means. It is the means that determine the ends.

            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