views:

9

answers:

1

Hi,

I have a sqldatareader populated with this command:

string cmdlookup = String.Format("Select {0} from {1}", strSourceName, strSourceTable);
  SqlCommand sqlcom = new SqlCommand(cmdlookup, con);
SqlDataReader rdrsource = cmd.ExecuteReader();


            while (rdrsource.Read())
            {


                this.lstSourceValues.Add(System.Convert.ToString(rdrsource[strSourceName]));



            }
            rdrsource.Close();

There is a function elsewhere in the program to modify this table. I have verified that it does indeed update the table in question. The table now has 11 values.

This results of this query NEVER CHANGES. It always returns 5 rows, even though a function elsewhere in the application has clearly updated the table. A few lines below I close the connection, too.

Is this thing cached somehow? Why doesn't the query update?

A: 

I was able to resolve the issue. The problem was that when I was calling .Close() and/or .Dispose(), it wasn't really getting rid of the object.

Instead, I needed to switch to using a using construct. For some reason, when I used the using construct, it definitely closed deleted the object.

It didn't change because I was continually getting the same in-memory representation of the object.

rsteckly

related questions