B
Bill Priess
Hey gang,
Ok, I'm stumped on this one... I am using the using statement to wrap a
SqlDataAdapter that I am using to fill a DataTable. Now, what I need to know
is, just how much block-scope applies to objects created in the using scope.
For example:
<code>
static DataTable getTable()
{
using (SqlDataAdapter sda = new SqlDataAdapter("StoredProcedure", new
SqlConnection("ConnectionString")))
{
DataTable dt = new DataTable("table");
sda.Fill(dt);
return dt;
}
}
</code>
I know this would return a table with zero rows becuase it is created and
destroyed within the scope of the using statement. But...
<code>
static DataTable getTable()
{
DataTable dt = new DataTable("table");
using (SqlDataAdapter sda = new SqlDataAdapter("StoredProcedure", new
SqlConnection("ConnectionString")))
{
sda.Fill(dt);
}
return dt;
}
</code>
Now, when I call this, I also get back zero rows in my table, yet when I run
the query in SQL, it comes back fine. Anyone have any ideas or experience
with the using statement?
TIA,
Bill P.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCM/MU/B dpu s--:-- a32 C++++$ ULH+++ P+++ L++ E+ W+++$ N++ o K? w++++$ O--
M V-- PS+ PE+ Y++ PGP++ t++@ 5++@ X++ R+@ tv b++ DI++ D+++>++++ G++ e++
h---- r+++ y++++
-----END GEEK CODE BLOCK-----
Ok, I'm stumped on this one... I am using the using statement to wrap a
SqlDataAdapter that I am using to fill a DataTable. Now, what I need to know
is, just how much block-scope applies to objects created in the using scope.
For example:
<code>
static DataTable getTable()
{
using (SqlDataAdapter sda = new SqlDataAdapter("StoredProcedure", new
SqlConnection("ConnectionString")))
{
DataTable dt = new DataTable("table");
sda.Fill(dt);
return dt;
}
}
</code>
I know this would return a table with zero rows becuase it is created and
destroyed within the scope of the using statement. But...
<code>
static DataTable getTable()
{
DataTable dt = new DataTable("table");
using (SqlDataAdapter sda = new SqlDataAdapter("StoredProcedure", new
SqlConnection("ConnectionString")))
{
sda.Fill(dt);
}
return dt;
}
</code>
Now, when I call this, I also get back zero rows in my table, yet when I run
the query in SQL, it comes back fine. Anyone have any ideas or experience
with the using statement?
TIA,
Bill P.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCM/MU/B dpu s--:-- a32 C++++$ ULH+++ P+++ L++ E+ W+++$ N++ o K? w++++$ O--
M V-- PS+ PE+ Y++ PGP++ t++@ 5++@ X++ R+@ tv b++ DI++ D+++>++++ G++ e++
h---- r+++ y++++
-----END GEEK CODE BLOCK-----