As per my updated solution on your post
getting error as Must declare the scalar variable "@tea_id"[
^]
The problem is with
String tea_id = Convert.ToString(TextBox2.Text);
Firstly
TextBox2.Text
is already a String, so no need to convert it.
Secondly it would appear that Teacher_id is probably an integer or a long. Because you have declared tea_id as a string, the line
command.Parameters.AddWithValue("@tea_id", tea_id);
will result in a SQL command of
SELECT * from Question WHERE Teacher_id='9999'
(where 9999 is whatever was in TextBox2). Note the single quotes around '9999' - i.e. a varchar as far as SQL is concerned.
If you make the correction I have suggested then you will get a SQL command of
SELECT * from Question WHERE Teacher_id=9999
i.e.
long tea_id=long.Parse(TextBox2.Text);
Note: the
TryParse
method is usually better when accepting input from a user, I've only used
Parse
for brevity here.