SQL and loops
-
By a factor of 210. Instead of 210 calls to the database, you make one, and then get all the values back into a local object that you can step through to find the replies. If the questions are multiple choice, and there are always 210 questions, then there are reasons to put an answer per column, in terms of being able to query the data. I'd just name them Answer1, Answer2 or something, so I didn't need to use [] all the time. Actually, even then I think I'd be more inclined to do a table that contains the student ID, the question ID and the answer in three columns, which would allow me to have as many or as few questions as I liked, still search the database for answers, and not waste any space. Christian Graus - Microsoft MVP - C++
-
By a factor of 210. Instead of 210 calls to the database, you make one, and then get all the values back into a local object that you can step through to find the replies. If the questions are multiple choice, and there are always 210 questions, then there are reasons to put an answer per column, in terms of being able to query the data. I'd just name them Answer1, Answer2 or something, so I didn't need to use [] all the time. Actually, even then I think I'd be more inclined to do a table that contains the student ID, the question ID and the answer in three columns, which would allow me to have as many or as few questions as I liked, still search the database for answers, and not waste any space. Christian Graus - Microsoft MVP - C++
-
The idea is that we will use Crystal Reports to print the answers of each or a specific student in a specific format. But why we should use []?!!
mhmo wrote: The idea is that we will use Crystal Reports to print the answers of each or a specific student in a specific format. OK - either way, I think the data format I've specified is better, but I'm not familiar with Crystal Reports. If it needs all the values to be in one row, that would just be crap though. mhmo wrote: But why we should use []?!! Because a number on it's own is a reserved value, it's not really an acceptable column name. The [] tells it we used bad column names, and asks it to live with it. Christian Graus - Microsoft MVP - C++
-
Hi I have a table (named information) that contains columns with the names (1,2,3,4,5,6,7,8,...210) I entered a loop from i=1 to i=210 and inside the loop I write the following SQL statement: string an = "SELECT " + i.ToString() + " FROM information WHERE id = '" + s.Id + "';"; I should get the string contained in the column named i but what I get is i itself:(:( Whay would be the problem
-
mhmo wrote: The idea is that we will use Crystal Reports to print the answers of each or a specific student in a specific format. OK - either way, I think the data format I've specified is better, but I'm not familiar with Crystal Reports. If it needs all the values to be in one row, that would just be crap though. mhmo wrote: But why we should use []?!! Because a number on it's own is a reserved value, it's not really an acceptable column name. The [] tells it we used bad column names, and asks it to live with it. Christian Graus - Microsoft MVP - C++
-
Just a hint: Read up on how others have structured a multi-choice test in a database. Your table schema is plain crazy!
-
mhmo wrote: The idea is that we will use Crystal Reports to print the answers of each or a specific student in a specific format. OK - either way, I think the data format I've specified is better, but I'm not familiar with Crystal Reports. If it needs all the values to be in one row, that would just be crap though. mhmo wrote: But why we should use []?!! Because a number on it's own is a reserved value, it's not really an acceptable column name. The [] tells it we used bad column names, and asks it to live with it. Christian Graus - Microsoft MVP - C++
>... but I'm not familiar with Crystal Reports. If it needs all the values to be in one row, that would just be crap though. You can pivot data in Crystal, but it's still crap.
-
Did you manually type in every column name? :doh: What is the deal with schools these days? Do they just tell you to use a database for something, without teaching you anything at all about how to use a database, or how to design your tables, etc.? Matt Gerrans
-
Did you manually type in every column name? :doh: What is the deal with schools these days? Do they just tell you to use a database for something, without teaching you anything at all about how to use a database, or how to design your tables, etc.? Matt Gerrans