0

I have problem with this code and I don't know why that is.

Code:

SqlConnection getconn = new SqlConnection(somthing secured);              
string sql = "select  pk_stu_id , stu_name   from MRK , STU , LSN where fk_stu_id = pk_stu_id and fk_lsn_id = pk_lsn_id AND pk_lsn_id="
      + int.Parse(textBoxSearchStudentID.Text)
      + " and pk_stu_id="
      + int.Parse(textBoxSearchLessonID.Text); 



SqlCommand cmd = new SqlCommand(sql, getconn);
getconn.Open();
SqlDataReader result  = cmd.ExecuteReader();
while (result.Read())
{
    textBoxDataSend.Text = string.Empty;
    textBoxDataSend.Text = result.ToString();
}
getconn.Close();

But it just always returns: "System.Data.SqlClient.SqlDataReader".

Does anyone know how to fix this?

2
  • are you able to run it now? Commented Dec 8, 2013 at 14:39
  • yes bro it works.thnx Commented Dec 13, 2013 at 5:25

2 Answers 2

2

Problem : you are directly assigning SqlDataReader obect to your TextBox.

Solution : you need to access the required columns returned by your query using SqlDataReader object by providing either by column name or column index.

Replace this:

textBoxDataSend.Text = result.ToString();

with this:

textBoxDataSend.Text = result["stu_name"].ToString();//or you can give any other column name here
Sign up to request clarification or add additional context in comments.

Comments

0

Any object if ToString() is used for that will give you what kind of object it is, unless ToString() is override specifically inside the class.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.