一样用嘛public static DataSet ExecuteDataset(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
{
if( transaction == null ) throw new ArgumentNullException( "transaction" );
if( transaction != null && transaction.Connection == null ) throw new ArgumentException( "The transaction was rollbacked or commited, please provide an open transaction.", "transaction" ); // Create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection );
// Create the DataAdapter & DataSet
using( SqlDataAdapter da = new SqlDataAdapter(cmd) )
{
DataSet ds = new DataSet(); // Fill the DataSet using default values for DataTable names, etc
da.Fill(ds);
// Detach the SqlParameters from the command object, so they can be used again
cmd.Parameters.Clear(); // Return the dataset
return ds;
}
}
{
if( transaction == null ) throw new ArgumentNullException( "transaction" );
if( transaction != null && transaction.Connection == null ) throw new ArgumentException( "The transaction was rollbacked or commited, please provide an open transaction.", "transaction" ); // Create a command and prepare it for execution
SqlCommand cmd = new SqlCommand();
bool mustCloseConnection = false;
PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection );
// Create the DataAdapter & DataSet
using( SqlDataAdapter da = new SqlDataAdapter(cmd) )
{
DataSet ds = new DataSet(); // Fill the DataSet using default values for DataTable names, etc
da.Fill(ds);
// Detach the SqlParameters from the command object, so they can be used again
cmd.Parameters.Clear(); // Return the dataset
return ds;
}
}
string str=@"Provider=MicroSoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\LG\My Documents\db2.mdb";
string SQL="select * from 表1";
OleDbConnection conn = new OleDbConnection(str);
conn.Open();
OleDbCommand cmd = new OleDbCommand(SQL,conn);
OleDbDataAdapter adt = new OleDbDataAdapter();
adt.SelectCommand=cmd;
DataSet ds = new DataSet();
adt.Fill(ds);
conn.Close();
this.dataGrid1.DataSource = ds.Tables[0].DefaultView;
ds.Clear();
head是出来了,但数据项为空
//this.dataGrid1.DataSource = ds.Tables[0].DefaultView;dataGrid1.DataSource = ds;
dataGrid1.DataMember = "数据表";conn.Close();
//ds.Clear();
请问如何处理?
请问如何处理?