我在Microsoft SQL Server 2005數據庫中有一個名爲t_Student
的表。在該表中有三列,分別爲student_regiNo
,student_Name
,student_Email
。從MS SQL Server 2005中選擇數據
我正在使用以下代碼段來檢索「student_Name」。但不是顯示「student_Name」,而是顯示「System.Data.SqlClient.SqlDataReader」。有什麼問題?
private void GetDatabaseConnection()
{
string connectionString = @"server=RZS-F839AD139AA\SQLEXPRESS; Integrated Security = SSPI; database = StudentCourseInformation";
connection = new SqlConnection(connectionString);
connection.Open();
}
public string GateStudentName(string selectedStudentRegiNo)
{
GetDatabaseConnection();
string selectedStudentQuery = @"SELECT student_Name FROM t_Student WHERE (
student_regiNo =
'" +selectedStudentRegiNo+ @"'
)";
SqlCommand command = new SqlCommand(selectedStudentQuery, connection);
SqlDataReader reader = command.ExecuteReader();
string selectedStudentName = Convert.ToString(reader);
return selectedStudentName;
}
感謝abatishchev爲您寶貴的建議。 – Towhid 2010-08-16 08:01:35
@towhidulbashar:不客氣:)不要忘記接受正確的答案。在這裏,在你的其他隊列 – abatishchev 2010-08-16 08:07:36