반응형
// 데이터베이스 위치 정보 및 계정 정보를 저장하는 연결 문자열
string strCon = "server=localhost;database=intra;uid=intra;pwd=intra";
// 데이터베이스와 연결을 담당하는 객체 생성
// 연결 문자열을 파라미터로 전달
MySqlConnection connection;
connection = new MySqlConnection();
connection.ConnectionString = strCon;
connection.Open();
string strQuery = "select * from message ";
MySqlCommand cmd = connection.CreateCommand();
cmd.CommandText = strQuery;
cmd.CommandType = CommandType.Text;
MySqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Response.Write(String.Format("{0}, {1}, {2}, {3}",
reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3)) + "<br/>");
}
connection.Close();
반응형
'Programming' 카테고리의 다른 글
Web.config에서 변수 선언해서 데이터베이스 연결주소 저장하기. (0) | 2010.06.09 |
---|---|
.net 가상의 데이터 베이스에 자료를 입력해 데이터를 출력하기. (0) | 2010.06.08 |
.net과 mysql 연동하기 (0) | 2010.06.07 |
Boxing 과 Unboxing (0) | 2010.04.30 |