Click here to Skip to main content
16,016,744 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, please i am implementing a result system whereby the names of students from their respective classes are retrieved based on a unique ID and their results are entered in the respective subject fields. i wanted to implement this with a formview, whereby the user can enter the student Id and class and the student name is retrieved along with the subject fields, then the subjects can be entered. i tried this;

C#
conn.Open();
        String sql = "select * from" + classDropDown.Text + "where id='" + idtbox.Text + "'";
        using (SqlDataAdapter adapter = new SqlDataAdapter(sql, conn))
        {

            DataTable table = new DataTable();
            adapter.Fill(table);
            FormView1.DataSource = table;
            FormView1.DataBind();
        }
    }


since each class has a different table, but this is not working. Please suggest to me what other method to use or how i can implement this using formview control.
Thanks for taking time out to read this.
Posted
Comments
[no name] 16-Jul-14 19:00pm    
What would you expect "select * fromsometablenamewhere id='sometext'" to do?
"not working" means nothing to anyone but you. Learn how to describe an actual problem.
Learn to write a real query, start a www.w3schools.com
Then do some research to find out why string concatenation is a bad way to construct SQL queries.
Member 10920447 16-Jul-14 19:46pm    
do you have any suggestions how i could make this work, i explained what i intended to do, what control or method can i use for this just mention and i'll do the research on it. thanks.
Per Söderlund 17-Jul-14 1:36am    
don´t use "'" if id is an integer, also make sure you have space after from and where like this, "from "," where".
Really, look up on parameterized query,it will make your queries alot more solid.

0) where id='" + idtbox.Text + "'"; -- please don't use concatenation; use a parameterized query.
1) "each class has a different table" -- that's a bad idea.
2) "formview" -- I have no idea what that is.

Otherwise it looks OK; what is it not doing?
 
Share this answer
 
HI Since you have already designed the database though please make sure on below points at the time of query generation

1. classDropDown.Text name should be exactly same as there in data base so it would be better if you could use the Dropdown with Friendly text and value with names of Tables.

2. Better make the Student Id gets inputted in text box with small length
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900