hi there…
using command: SqlCommand := new SqlCommand('select data_type from information_schema.columns where table_name = '+chr(39)+tablename+chr(39)+' and column_name = '+chr(39)+ZFrom+chr(39), connection) do begin
using reader: SqlDataReader := command.ExecuteReader() do begin
if not reader.HasRows then
raise new Exception('Field '+ZFrom+' not found in table');
reader.Read();
var s:= reader.GetString(0);
if not contains(MSSQL_Numbers, s) then
raise new Exception('Field '+ZFrom+' is wrong type');
reader.Close();
end;
end;
this block is an example, that is currently working.
However I needed to use that reader.Close() at the end, so that the next block (similar to this one) works !
If I do not call this reader.Close() the next query will return the values from the first query made. Only expliciting calling the Close on the reader I can effectivelly get data from a new query.
Looking up for this in C# I see 2 types of contructions, one where Using clause is used extensivelly, like I did, and supposedly when reader is disposed, close() is called automatically.The other construction is doing every step with the using clause for controlling context.
I am not sure this is an Oxigene thing, or I did not understand how reader and using works together.
RIght now, I have to add this reader.Close() everywhere in my code before the reader gets out of context.
Any clue?