Cyber-Drugs
asked on
C# - Re-using a DataAdapter
Hi guys 'n gals,
I wanted to know if there is a way so consolidate my code, by maybe re-using my DataAdapter variable, rather than creating a new one for each query to the database? Here is how my code looks at the moment:
void FillDataTables()
{
MySqlConnection conn = new MySqlConnection(connString );
DataSet ds = new DataSet();
conn.Open();
MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM tblConnections", conn);
adapter.Fill(ds);
adapter = null;
MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM tblInspector", conn);
adapter.Fill(ds);
conn.Close();
MessageBox.Show(ds.Tables. Count.ToSt ring());
}
It throws the following error:
Error 1 A local variable named 'adapter' is already defined in this scope
Any ideas on getting past this?
Cheers guys!
I wanted to know if there is a way so consolidate my code, by maybe re-using my DataAdapter variable, rather than creating a new one for each query to the database? Here is how my code looks at the moment:
void FillDataTables()
{
MySqlConnection conn = new MySqlConnection(connString
DataSet ds = new DataSet();
conn.Open();
MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM tblConnections", conn);
adapter.Fill(ds);
adapter = null;
MySqlDataAdapter adapter = new MySqlDataAdapter("SELECT * FROM tblInspector", conn);
adapter.Fill(ds);
conn.Close();
MessageBox.Show(ds.Tables.
}
It throws the following error:
Error 1 A local variable named 'adapter' is already defined in this scope
Any ideas on getting past this?
Cheers guys!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cheers!