Getting a particular field from a database
-
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
-
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
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
-
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
-
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
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?
-
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?
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
-
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
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?
-
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
//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