간단한 로그인 페이지가 있습니다. 내가하고 싶은 일은 로그인이 올 바르며 모든 열을 표시하고 싶습니다. while 루프에 표시 할 열을 수동으로 지정하고 싶지는 않습니다.열을 지정하지 않고 데이터베이스의 데이터 표시
private void Authenticate(string userName, string password)
{
string connString = "server=.\\sqlexpress; database=TestDatabase; trusted_connection=true";
SqlConnection conn = new SqlConnection(connString);
conn.Open();
string sqlCommand = "select * from Registration where UserName='" + userName + "' and Password='" + password + "'";
SqlCommand command = conn.CreateCommand();
command.CommandText = sqlCommand;
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
lblResult.Text += reader["CourseId"] + " " + reader["CourseName"] + " " + reader["Instructor"] + "<br />";
}
}
나는 이것이 최선의 구현 아니라는 것을 알고 :
이
에서는 SQL Server 2008 Express를 사용하여 C#에서 내가 가진 샘플입니다.등록 테이블에서 반환되는 모든 항목으로 lblResult를 어떻게 채울 수 있습니까?
LINQ + DataSource? – Christian
당신은 서수 위치 – MethodMan
에 의해 독자 []에 액세스 할 수 있습니다. 여기서 UserName = ' "+ userName +"'--- 정말요 ?? Google SqlParameters –