본문 바로가기
Programming

.net 가상의 데이터 베이스에 자료를 입력해 데이터를 출력하기.

by Mizix 2010. 6. 8.
반응형
// 데이터베이스 위치 정보 및 계정 정보를 저장하는 연결 문자열
            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>";
            }
반응형