请教一下,关于利用command读取信息,如果进行创建表?
OracleConnection conn = new OracleConnection(MyDBSorce.getConnString());
OracleCommand selsql = new OracleCommand( "select * from t_truck ", conn);
conn.Open();
OracleDataReader readtruck = selsql.ExecuteReader();
DataTable tb = new DataTable ();
如题,代码如上,如果把select语句读到的信息添加到tb里?
------解决方案--------------------楼主如果你用DataAdapter这件事非常容易做
OracleConnection conn = new OracleConnection(MyDBSorce.getConnString());
OracleDataAdapter da = new OracleDataAdapter( "select * from t_truck ", conn);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds);
conn.Close();
DataTable tb = ds.Tables[0];
------解决方案--------------------如果你坚持用DataReader,就只能
while(readtruck.Read())
{
//自己一行一行写到DataTable的DataRow中
}
------解决方案--------------------OracleConnection conn = new OracleConnection(MyDBSorce.getConnString());
OracleCommand selsql = new OracleCommand( "select * from t_truck ", conn);
conn.Open();
OracleDataReader readtruck = selsql.ExecuteReader();
DataTable tb = new DataTable ();
tb.Load( readtruck );