반응형
// 데이터베이스 위치 정보 및 계정 정보를 저장하는 연결 문자열
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();
//데이터베이스 연결 및 쿼리 명령문 실행.
MySqlDataAdapter adapter = new MySqlDataAdapter(strQuery,connection);
//가상의 데이터베이스 생성.
DataSet ds = new DataSet("VirtualNorthwind");
//가상의 데이터베이스에 테이블 셍성 후 레토드 저장
adapter.Fill(ds,"VurtualCustomers");
//가상의 테이블의 고객 정보를 출력
Label1.Text = "<b>고객 정보 </b><hr>";
for (int i = 0; i < ds.Tables["VurtualCustomers"].Rows.Count;i++)
{
DataRow row = ds.Tables["VurtualCustomers"].Rows[i];
Label1.Text += row["Enrty_ID"].ToString() + ", " + row["Name"].ToString() + ", " + row["Email"] + ", " + row["Message"] +"<br>";
}
반응형
'Programming' 카테고리의 다른 글
게시판 리스트 처리. (0) | 2010.06.10 |
---|---|
Web.config에서 변수 선언해서 데이터베이스 연결주소 저장하기. (0) | 2010.06.09 |
.net 에서 MySQL 데이터 읽어오기. (0) | 2010.06.08 |
.net과 mysql 연동하기 (0) | 2010.06.07 |