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. Windows Forms
  4. DataBind to specific records

DataBind to specific records

Scheduled Pinned Locked Moved Windows Forms
csstutorialquestion
6 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.
  • K Offline
    K Offline
    kensai
    wrote on last edited by
    #1

    I have a DataGridView binded to this table:

    [Users]
    ID Name


    11 Qwe
    22 Asd

    Grid is directly binded with a typed dataset. I have a second table like this:

    [Records]
    ID UserID Data


    67 11 ....
    68 11 ....

    Records.UserID is connected to Users with a foreign key. What I want to do is: when the user doubleclicks User #11 I open a new grid, binded to Records table but only binded to rows where UserID = 11. Doubleclick, getting ID, new grid etc. those are I'm OK with. I wouldn't had any problems if I was doing this connected with sprocs but I want it to be binded and I simply have no idea how to do this. Can you please give me any ideas?

    M 1 Reply Last reply
    0
    • K kensai

      I have a DataGridView binded to this table:

      [Users]
      ID Name


      11 Qwe
      22 Asd

      Grid is directly binded with a typed dataset. I have a second table like this:

      [Records]
      ID UserID Data


      67 11 ....
      68 11 ....

      Records.UserID is connected to Users with a foreign key. What I want to do is: when the user doubleclicks User #11 I open a new grid, binded to Records table but only binded to rows where UserID = 11. Doubleclick, getting ID, new grid etc. those are I'm OK with. I wouldn't had any problems if I was doing this connected with sprocs but I want it to be binded and I simply have no idea how to do this. Can you please give me any ideas?

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      I would use a dataview to service the records gridview. When the user double clicks you set the rowfiler of the dataview Dataview1.RowFilter = String.format("UserID = {0}",UserIDValue) changing the filter of the dataview automatically updates the records gridview

      Never underestimate the power of human stupidity RAH

      K 1 Reply Last reply
      0
      • M Mycroft Holmes

        I would use a dataview to service the records gridview. When the user double clicks you set the rowfiler of the dataview Dataview1.RowFilter = String.format("UserID = {0}",UserIDValue) changing the filter of the dataview automatically updates the records gridview

        Never underestimate the power of human stupidity RAH

        K Offline
        K Offline
        kensai
        wrote on last edited by
        #3

        Thanks for the reply. The problem with Filter is that you have to retrieve all of the records first, than display the ones according to filter. Is there a way to retrieve just the records you want in the first place?

        M 1 Reply Last reply
        0
        • K kensai

          Thanks for the reply. The problem with Filter is that you have to retrieve all of the records first, than display the ones according to filter. Is there a way to retrieve just the records you want in the first place?

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          kensai wrote:

          Is there a way to retrieve just the records you want in the first place?

          But of course. You have the userid, create a proc that returns the records for that user and bind the resulting datatable to the datasource. Changing datasource is a standard operation!

          Never underestimate the power of human stupidity RAH

          K 1 Reply Last reply
          0
          • M Mycroft Holmes

            kensai wrote:

            Is there a way to retrieve just the records you want in the first place?

            But of course. You have the userid, create a proc that returns the records for that user and bind the resulting datatable to the datasource. Changing datasource is a standard operation!

            Never underestimate the power of human stupidity RAH

            K Offline
            K Offline
            kensai
            wrote on last edited by
            #5

            Unfortunately, the database is Sql Server CE which doesn't support sprocs :sigh: I think I need a way to bind data to a tableadapter custom method which returns records according to a parameter, in this case ID. No idea how to do this though :-O

            M 1 Reply Last reply
            0
            • K kensai

              Unfortunately, the database is Sql Server CE which doesn't support sprocs :sigh: I think I need a way to bind data to a tableadapter custom method which returns records according to a parameter, in this case ID. No idea how to do this though :-O

              M Offline
              M Offline
              Mycroft Holmes
              wrote on last edited by
              #6

              How do you get your data now, presumably SQL strings if procs are not supported. What's wrong with the following. Select * from Records where UserID = iUserID

              Never underestimate the power of human stupidity RAH

              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