OLEDB version

 /// <summary>
 /// 데이터셋 
 /// 사용법
 /// DataTable table;
 /// FamilyBook.db.Dbconn dbconn = new FamilyBook.db.Dbconn();    
 /// table= dbconn.getTable("select * from SUB_FAMILY order by ref desc,pos asc ");    
 /// System.Data.DataRowCollection rows = table.Rows;
 /// foreach (DataRow dr in rows){
 /// dr["ref"].ToString();
 ///}
 /// </summary>
 /// <param name="str">쿼리문</param>
 /// <returns>DataTable</returns>

  public DataTable  getTable(string str){     
   adapter= new OleDbDataAdapter();  
   adapter.SelectCommand = new OleDbCommand(str,conn ); 
   DataSet ds = new DataSet();
   adapter.Fill(ds);
   conn.Close();
   DataTable table= ds.Tables[0]; 
   return table;
  }

SQL version

   System.Data.SqlClient.SqlDataAdapter sqlAp = new System.Data.SqlClient.SqlDataAdapter("SELECT * FROM      SUB_FAMILY" , dbconn.GetConnection() );
   System.Data.DataTable dt  = new System.Data.DataTable();
   System.Data.DataSet ds = new System.Data.DataSet();

   sqlAp.Fill(dt);
   System.Data.DataRowCollection rows =dt.Rows;
   foreach (DataRow dr in rows){
   System.Windows.Forms.MessageBox.Show( dr["name"].ToString() );
   } 

+ Recent posts