//连接数据库假设为Access数据库 string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=domain.mdb;Persist Security Info=True"; OleDbConnection myconn = new OleDbConnection(strCon); //查询数据 DataSet ds = new DataSet(); try { myconn.Open(); OleDbDataAdapter oda = new OleDbDataAdapter("select * from A", myconn); oda.Fill(ds); return ds; } catch (Exception ex) { throw ex; } finally { if (myconn.State == System.Data.ConnectionState.Open) { myconn.Close(); } }
//赋值 DataTable dt = ds.Table[0]; string x = dt.Rows[0]["a"].toString(); string y = dt.Rows[0]["b"].toString(); string y = dt.Rows[0]["c"].toString();
第2个回答 2008-12-29
很简单的咯
DataSet ds = new DataSet(); string x = ds.Tables[0].Rows[0][0].ToString(); string y = ds.Tables[0].Rows[0][1].ToString(); string z = ds.Tables[0].Rows[0][2].ToString();