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. Web Development
  3. ASP.NET
  4. Getting a particular field from a database

Getting a particular field from a database

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netdatabasetutorial
7 Posts 4 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.
  • A Offline
    A Offline
    alee15 10 88
    wrote on last edited by
    #1

    Hi all, I am doing a website with asp.net and I would like to know how to get a particular field from a database. After that the user log ins, I need to know if the user is a student or a teacher by checking the occupation that is saved in the table Userlogins in the Database. I tried to do something like the following but unfortunately it did not work //ds is the typed Data Set //UserloginsDataTable is the table where the occupation is saved //Occupation is the name of the column if(ds.UserloginsDataTable[0].Occupation.ToString().ToUpper() == "STUDENT") { } Can anyone tell me if I am doing it right and if yes why isn't it working Thanks a lot guys

    C P K 3 Replies Last reply
    0
    • A alee15 10 88

      Hi all, I am doing a website with asp.net and I would like to know how to get a particular field from a database. After that the user log ins, I need to know if the user is a student or a teacher by checking the occupation that is saved in the table Userlogins in the Database. I tried to do something like the following but unfortunately it did not work //ds is the typed Data Set //UserloginsDataTable is the table where the occupation is saved //Occupation is the name of the column if(ds.UserloginsDataTable[0].Occupation.ToString().ToUpper() == "STUDENT") { } Can anyone tell me if I am doing it right and if yes why isn't it working Thanks a lot guys

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      alee15.10.88 wrote:

      I tried to do something like the following but unfortunately it did not work

      alee15.10.88 wrote:

      Can anyone tell me if I am doing it right and if yes why isn't it working

      What do you mean by "not working" what are the symptoms? Do you get a compiler error? A runtime error? What?


      "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

      A 1 Reply Last reply
      0
      • A alee15 10 88

        Hi all, I am doing a website with asp.net and I would like to know how to get a particular field from a database. After that the user log ins, I need to know if the user is a student or a teacher by checking the occupation that is saved in the table Userlogins in the Database. I tried to do something like the following but unfortunately it did not work //ds is the typed Data Set //UserloginsDataTable is the table where the occupation is saved //Occupation is the name of the column if(ds.UserloginsDataTable[0].Occupation.ToString().ToUpper() == "STUDENT") { } Can anyone tell me if I am doing it right and if yes why isn't it working Thanks a lot guys

        P Offline
        P Offline
        ptvce
        wrote on last edited by
        #3

        i think if u write the table name u should not write the table[0]; u can write: ds.tabel[0].row[1][2].tostring() == "student"; 1 is the num of ur row and 2 is the num of ur column

        1 Reply Last reply
        0
        • C Colin Angus Mackay

          alee15.10.88 wrote:

          I tried to do something like the following but unfortunately it did not work

          alee15.10.88 wrote:

          Can anyone tell me if I am doing it right and if yes why isn't it working

          What do you mean by "not working" what are the symptoms? Do you get a compiler error? A runtime error? What?


          "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

          A Offline
          A Offline
          alee15 10 88
          wrote on last edited by
          #4

          Actually it's working... but it isn't logging on with any accounts i'm trying with. The underneath is the code I have in the button submit string occupation = (UHandler.UserLogIns.Rows[0]["Occupation"].ToString().ToUpper()); if(occupation == "STUDENT") { Session["userID"] = txtUsername.Text; Response.Redirect("UsersViewProfile.aspx"); } The problem is that I do not have a row filter which returns that 1 particular row, so it's searching in the first row where the occupation of that row is Teacher. Did you understand me now?

          C 1 Reply Last reply
          0
          • A alee15 10 88

            Actually it's working... but it isn't logging on with any accounts i'm trying with. The underneath is the code I have in the button submit string occupation = (UHandler.UserLogIns.Rows[0]["Occupation"].ToString().ToUpper()); if(occupation == "STUDENT") { Session["userID"] = txtUsername.Text; Response.Redirect("UsersViewProfile.aspx"); } The problem is that I do not have a row filter which returns that 1 particular row, so it's searching in the first row where the occupation of that row is Teacher. Did you understand me now?

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            alee15.10.88 wrote:

            Actually it's working... but it isn't logging on with any accounts i'm trying with.

            In other words it is not working due to a logic error.

            alee15.10.88 wrote:

            The problem is that I do not have a row filter which returns that 1 particular row, so it's searching in the first row where the occupation of that row is Teacher.

            Why are you returning so many rows? If you only need one row what are the rest for? Do you only need one column value as well? If you do need all these rows why not search for the row that you want? (Or is that what you are really asking for?) Sorry, I'm still not sure how to help you, but the answers to the questions above may help get to the answer.


            "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

            A 1 Reply Last reply
            0
            • C Colin Angus Mackay

              alee15.10.88 wrote:

              Actually it's working... but it isn't logging on with any accounts i'm trying with.

              In other words it is not working due to a logic error.

              alee15.10.88 wrote:

              The problem is that I do not have a row filter which returns that 1 particular row, so it's searching in the first row where the occupation of that row is Teacher.

              Why are you returning so many rows? If you only need one row what are the rest for? Do you only need one column value as well? If you do need all these rows why not search for the row that you want? (Or is that what you are really asking for?) Sorry, I'm still not sure how to help you, but the answers to the questions above may help get to the answer.


              "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

              A Offline
              A Offline
              alee15 10 88
              wrote on last edited by
              #6

              I'm sorry that I'm not explaining well. But actually that's what I want... to search that particular row by using a row filter. any idea?

              1 Reply Last reply
              0
              • A alee15 10 88

                Hi all, I am doing a website with asp.net and I would like to know how to get a particular field from a database. After that the user log ins, I need to know if the user is a student or a teacher by checking the occupation that is saved in the table Userlogins in the Database. I tried to do something like the following but unfortunately it did not work //ds is the typed Data Set //UserloginsDataTable is the table where the occupation is saved //Occupation is the name of the column if(ds.UserloginsDataTable[0].Occupation.ToString().ToUpper() == "STUDENT") { } Can anyone tell me if I am doing it right and if yes why isn't it working Thanks a lot guys

                K Offline
                K Offline
                Kanjinghat
                wrote on last edited by
                #7

                //ds is the typed Data Set //UserloginsDataTable is the table where the occupation is saved //Occupation is the name of the column try this one if(ds.Tables["UserloginsDataTable"].Select("Occupation=Student").Length>0) { } ds.Tables["UserloginsDataTable"].Select("Occupation=Student") will return a datarow array. and if the array length is<1 then ther are no records else records exixts. hope this helps you. Ramesh.Kanjinghat

                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