Click here to Skip to main content
15,908,115 members
Home / Discussions / C#
   

C#

 
GeneralToolbar Component Setting Pin
zuhx13-Nov-03 11:08
zuhx13-Nov-03 11:08 
GeneralRe: Toolbar Component Setting Pin
Heath Stewart14-Nov-03 2:37
protectorHeath Stewart14-Nov-03 2:37 
Generalhandling a voice event Pin
eafares26513-Nov-03 10:15
eafares26513-Nov-03 10:15 
GeneralRe: handling a voice event Pin
Kentamanos13-Nov-03 10:47
Kentamanos13-Nov-03 10:47 
GeneralRe: handling a voice event Pin
eafares26514-Nov-03 5:03
eafares26514-Nov-03 5:03 
GeneralBlock scope when using 'using' statement. Pin
Bill Priess13-Nov-03 6:29
Bill Priess13-Nov-03 6:29 
GeneralRe: Block scope when using 'using' statement. Pin
Heath Stewart13-Nov-03 7:06
protectorHeath Stewart13-Nov-03 7:06 
GeneralRe: Block scope when using 'using' statement. Pin
Bill Priess13-Nov-03 7:34
Bill Priess13-Nov-03 7:34 
Hey Heath,

Thanks for the quick reply... but... Wink | ;)

According to the docs:
selectCommandText
A String that is a Transact-SQL SELECT statement or stored procedure to be used by the SelectCommand property of the SqlDataAdapter.

I forgot to put in the fact that I use sda.SelectCommand.CommandType = CommandType.StoredProcedure.

Anyhow... I've tried it a number of different ways, all with the same problem.. the DataTable never has rows in it. I understand what you are saying, but, if the data adapter gets disposed *after* the fill, why would the data table still return no rows?

I did this and had the same results.

<br />
public static DataTable getTable()<br />
{<br />
    DataTable dt = new DataTable("table");<br />
    using (Config config = new Config()) //custom configuration class.<br />
    {<br />
        using (SqlConnection conn = new SqlConnection(config.SqlConnectionString))<br />
        {<br />
            using (SqlDataAdapter sda = new SqlDataAdatper("Select * from table", conn))<br />
            {<br />
                sda.Fill(dt);<br />
            }<br />
        }<br />
    }<br />
    return dt;<br />
}<br />
return dt;<br />


Now, from what I have read about the using statement, this pretty much translates to:
<br />
public static DataTable getTable()<br />
{<br />
    DataTable dt = new DataTable("table");<br />
    Config config = new Config();<br />
    try {<br />
        SqlConnection conn = new SqlConnection(config.SqlConnectionString);<br />
        try {<br />
            SqlDataAdapter sda = new SqlDataAdapter(SqlDataAdatper("Select * from table", conn));<br />
            try {<br />
                sda.Fill(dt);<br />
            }<br />
            finally {<br />
                if (sda!= null) ((IDisposable)sda).Dispose();<br />
            }<br />
        }<br />
        finally {<br />
            if (conn!= null) ((IDisposable)conn).Dispose();<br />
        }<br />
    }<br />
    finally {<br />
       if (config != null) ((IDisposable)config).Dispose();<br />
    }<br />
    return dt;<br />
}<br />
Believe it or not, when I run that code above, as is, it works fine. My table is populated and everyone is happy. Sorry to carry on, I am just trying to figure out the scope usage that MS wrote into the using statement.<br />
<br />
Any ideas? <br />
<br />
TIA,<br />
Bill P.<br />
Oakland, CA<br />
<hr size="2" noshade="" style="color: rgba(70, 130, 180, 1)">-----BEGIN GEEK CODE BLOCK-----<br />
Version: 3.21<br />
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++++<br />
-----END GEEK CODE BLOCK-----<br />
<hr size="2" noshade="" style="color: rgba(70, 130, 180, 1)">

GeneralRe: Block scope when using 'using' statement. Pin
Heath Stewart13-Nov-03 8:42
protectorHeath Stewart13-Nov-03 8:42 
GeneralRe: Block scope when using 'using' statement. Pin
Bill Priess13-Nov-03 9:54
Bill Priess13-Nov-03 9:54 
Generaldotnetmagic concepts Pin
mikemilano13-Nov-03 6:13
mikemilano13-Nov-03 6:13 
GeneralRe: dotnetmagic concepts Pin
Heath Stewart13-Nov-03 6:49
protectorHeath Stewart13-Nov-03 6:49 
GeneralCompiler error Pin
Jose Vicente13-Nov-03 5:16
Jose Vicente13-Nov-03 5:16 
GeneralRe: Compiler error Pin
Heath Stewart13-Nov-03 6:40
protectorHeath Stewart13-Nov-03 6:40 
GeneralRe: Compiler error Pin
Jose Vicente13-Nov-03 20:39
Jose Vicente13-Nov-03 20:39 
GeneralRe: Compiler error Pin
Heath Stewart14-Nov-03 1:59
protectorHeath Stewart14-Nov-03 1:59 
GeneralSimple question: PerformanceCounter Pin
CillyMe13-Nov-03 4:27
CillyMe13-Nov-03 4:27 
GeneralRe: Simple question: PerformanceCounter Pin
leppie13-Nov-03 6:25
leppie13-Nov-03 6:25 
GeneralRe: Simple question: PerformanceCounter Pin
CillyMe13-Nov-03 13:45
CillyMe13-Nov-03 13:45 
GeneralRe: Simple question: PerformanceCounter Pin
leppie13-Nov-03 14:05
leppie13-Nov-03 14:05 
GeneralC# and Excel Pin
Member 51858613-Nov-03 4:18
Member 51858613-Nov-03 4:18 
Generalhelp needed to create custom control which can arrange controls in polygonal shape. Pin
Shailaja13-Nov-03 4:08
Shailaja13-Nov-03 4:08 
GeneralRe: help needed to create custom control which can arrange controls in polygonal shape. Pin
Heath Stewart13-Nov-03 6:31
protectorHeath Stewart13-Nov-03 6:31 
GeneralDistributed Transaction Pin
CillyMe12-Nov-03 22:15
CillyMe12-Nov-03 22:15 
QuestionRichTextBox Change Picture?? Pin
electronicm12-Nov-03 22:14
electronicm12-Nov-03 22:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.