첫번째 데이터 셋을 우선 만들어야 한다.

변수선언

  private System.Data.OleDb.OleDbDataAdapter _DataAdapter;
  private System.Data.DataSet _DataSet;
  private System.Data.DataTable _DataTable;
  private System.Data.DataRowCollection _DataRowCollection ;
  private db.Dbconn dbconn = null;

  #region dataSet 을 만듭니다

  /// <summary>
  /// 데이터셋의 기본을 만듭니다. 데이터셋 등등
  /// </summary>
  public void MakeDataSet(){
   try
   {
    dbconn = new db.Dbconn();
    this._DataAdapter = new System.Data.OleDb.OleDbDataAdapter();
    this._DataAdapter.SelectCommand = new System.Data.OleDb.OleDbCommand("select * from test" , dbconn.GetConn() ); 

    this._DataSet = new System.Data.DataSet("main");
    this._DataAdapter.Fill( this._DataSet , "main");
    this._DataTable = this._DataSet.Tables[0];
    this._DataRowCollection = this._DataSet.Tables["main"].Rows;
    this.dataGrid1.DataSource = this._DataSet.Tables["main"];

   }
   catch(System.Exception es){
    MessageBox.Show(es.Message+" \n\n"+es.ToString() );
   }
  }

  #endregion 

this._DataSet 에 맞는 InsertCommand UpdateCommand 는 각각에 맞게 만들어주세요

만들어주지 않으면 실제로는 데이터베이스에 반영이 안됩니다.^^)b

ex)예제

   this._DataAdapter.InsertCommand = new System.Data.OleDb.OleDbCommand("INSERT INTO TEST (comm , page_num) VALUES( ? , ? )"  , dbconn.GetConn() );   
   this._DataAdapter.InsertCommand.Parameters.Add( "@comm" ,System.Data.OleDb.OleDbType.VarChar , 50 , "comm");
   this._DataAdapter.InsertCommand.Parameters.Add( "@page_num" ,System.Data.OleDb.OleDbType.VarChar , 50 , "page_num");

this._DataAdapter.Update(this._DataSet.Tables["main"]);

MSDN 에는 프로시저변수 "VALUES( @comm, @page_num )"   로 해도 되던데 나는 

그렇게 작업하니 오지게 안되더라 데브피아에 물어보니 OLEDB는 ? ? 로 작업을 해야된단다 ㅎㅎ

만들어진 데이터셋과 데이터 그리드 연결하기

this.dataGrid1.DataSource = this._DataSet.Tables["main"];

끝~

데이터 그리드에서  내가원하는 스탈로 디스플레이 하기

this._DataAdapter.SelectCommand = new System.Data.OleDb.OleDbCommand("select * from test" , dbconn.GetConn() );

select * from test 불러왔기때문에 모든 데이터 필드를 보여준다 하지만 사용자가 고유식별자

등등을 볼필요도 수정도 하면 안되기 때문에 바꿔준다 보기 좋게~

image

 

image

image

+ Recent posts