Thread View: borland.public.delphi.database.ado-net
1 messages
1 total messages
Started by Jeroen Vandezande
Mon, 04 Apr 2005 14:52
MySQLDataReader problem
Author: Jeroen Vandezande
Date: Mon, 04 Apr 2005 14:52
Date: Mon, 04 Apr 2005 14:52
82 lines
3703 bytes
3703 bytes
Hi all,
I am trying to get access to a MySQL server using Delphi 2005 in a pure .net
winforms app.
I use corelabs MySQL connector for .net to do this.
The problem is that the datareader does not shows the data from columns 6,7
and 8.
It gives no errors , the fields appear empty...
here is the code:
****************************************************************************************
program SQLTest;
{$APPTYPE CONSOLE}
uses
corelab.mysql;
var
param: MySqlParameter;
cmd: MySqlCommand;
SQLStatement: string;
reader: MySqlDataReader;
SQLConnection: MySqlConnection;
begin
SQLConnection := nil;
reader := nil;
try
SQLConnection := MySqlConnection.Create('User
Id=root;Password=delphi;Host=localhost;Database=pressurelogger');
SQLConnection.Open;
SQLStatement := 'SELECT (runtime * 20) AS numberofsamples, (fadeouttime
* 20) AS numberoffadeoutsamples, ' +
'tone1, tone2, tone1duration, tone2duration, pumpoffset,
cartridgename, shortname ' +
'FROM cartridges, operators, pumps ' +
'WHERE pumps.userid=operators.index ' +
'AND pumps.cartridgeid=cartridges.index ' +
'AND pumps.pumpipaddress=@IpAddress';
cmd := MySqlCommand.Create(SQLStatement, SQLConnection);
param := MySqlParameter.Create;
param.ParameterName := '@IpAddress';
param.Value := '192.168.10.15';
cmd.Parameters.Add(param);
reader := cmd.ExecuteReader;
while reader.Read do
begin
Console.WriteLine(reader['shortname']);
end;
finally
if (reader <> nil) then
reader.Close;
if (SQLConnection <> nil) then
SQLConnection.Close;
end;
end.
****************************************************************************************************************
as you can see I ask the datareader to print out the value of the collumn
'shortname'. (a string field).
This gives an empty field.
If I change the SQL statement to this :
SQLStatement := 'SELECT (runtime * 20) AS numberofsamples, (fadeouttime *
20) AS numberoffadeoutsamples, shortname, ' +
'tone1, tone2, tone1duration, tone2duration, pumpoffset,
cartridgename ' +
'FROM cartridges, operators, pumps ' +
'WHERE pumps.userid=operators.index ' +
'AND pumps.cartridgeid=cartridges.index ' +
'AND pumps.pumpipaddress=@IpAddress';
Then it works correctly!
The only thing I did was to put the shortname field on other place in the
select statement... still the last 3 fields are empty but the shortname
field is now field #3 and gets filled.
Can someone give me a solution to get all the fields working?
Best Regards,
Jeroen Vandezande.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads