Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB General » View Thread |
Messages 1 to 9 of 9 total |
EDBCommand and EDBDataReader |
Mon, Jul 7 2008 3:28 PM | Permanent Link |
David Loving | Trial Edition EDB-DAC-STD 2.0 (real thing on order) and the MS VS 2008 C# environment.
Great success with EDBCommand using .ExecuteNonQuery and .ExecuteScalar. Works fast and doesn't hog too much memory. No success with EDBCommand.ExecuteReader. I've had to resort to creating and disposing of a EDBDataAdapter and DataTable to hold a result set and that isn't near as quick or memory efficient when all I need is one record of data using a known primary key value. I think part of the problem is intellisense says the return value of EDBCommand.ExecuteReader is a DbDataReader instead of the EDBDataReader that I would like to work with. Any thoughts? Any suggestions of the fastest way to retrieve exactly one record of data from a known primary key value using EDBCommand? Thanks in advance! |
Mon, Jul 7 2008 4:17 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | David,
<< No success with EDBCommand.ExecuteReader. I've had to resort to creating and disposing of a EDBDataAdapter and DataTable to hold a result set and that isn't near as quick or memory efficient when all I need is one record of data using a known primary key value. I think part of the problem is intellisense says the return value of EDBCommand.ExecuteReader is a DbDataReader instead of the EDBDataReader that I would like to work with. >> Nah, that is just the class hierarchy at work - the resulting reader normally only uses common DbDataReader methods anyways, so it isn't likely that you'll need to cast it specifically to an EDBDataReader. << Any suggestions of the fastest way to retrieve exactly one record of data from a known primary key value using EDBCommand? >> What you want is this: { EDBCommand MyEDBCommand = new EDBCommand; try { MyEDBCommand.Connection = MyEDBConnection; MyEDBCommand.CommandText = "SELECT * FROM Customer WHERE CustNo=100"; MyEDBCommand.RequestLive = true; DbDataReader MyDataReader = MyEDBCommand.ExecuteReader(); try { MyDataReader.Read(); // Here you can use GetValue, GetString, GetInt32, etc. methods of the MyDataReader // to read the various row values MessageBox.Show(MyDataReader.GetString(0)); // Get first column value as string } finally { MyDataReader.Dispose(); } } finally { MyEDBCommand.Dispose(); } } -- Tim Young Elevate Software www.elevatesoft.com |
Mon, Jul 7 2008 4:50 PM | Permanent Link |
David Loving | Excellent! You are the man!
For anyone else interested, casting also worked on the returned object from a field name lookup such as... (int)MyDataReader["field_name"]; ...in place of... MyDataReader.GetInt32(0) So, Tim... what do we use EDBDataReader for??? David L. |
Tue, Jul 8 2008 2:44 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | David,
<< So, Tim... what do we use EDBDataReader for??? >> You're actually still using it, but just using it as its ancestor, the DbDataReader class. -- Tim Young Elevate Software www.elevatesoft.com |
Wed, Jul 9 2008 3:23 AM | Permanent Link |
Chris Holland SEC Solutions Ltd. Team Elevate | Hi David,
As you are using C# you can replace the try { EDBCommand MyEDBCommand = new EDBCommand .... } finally { MyEDBCommand.Dispose(); } by using: using(EDBCommand MyEDBCommand = new EDBCommand) { .... } Chris Holland [Team Elevate] Tim Young [Elevate Software] wrote: > David, > > << No success with EDBCommand.ExecuteReader. I've had to resort to creating > and disposing of a EDBDataAdapter and DataTable to hold a result set and > that isn't near as quick or memory efficient when all I need is one record > of data using a known primary key value. > > I think part of the problem is intellisense says the return value of > EDBCommand.ExecuteReader is a DbDataReader instead of the EDBDataReader that > I would like to work with. >> > > Nah, that is just the class hierarchy at work - the resulting reader > normally only uses common DbDataReader methods anyways, so it isn't likely > that you'll need to cast it specifically to an EDBDataReader. > > << Any suggestions of the fastest way to retrieve exactly one record of data > from a known primary key value using EDBCommand? >> > > What you want is this: > > { > EDBCommand MyEDBCommand = new EDBCommand; > try > { > MyEDBCommand.Connection = MyEDBConnection; > MyEDBCommand.CommandText = "SELECT * FROM Customer WHERE CustNo=100"; > MyEDBCommand.RequestLive = true; > DbDataReader MyDataReader = MyEDBCommand.ExecuteReader(); > try > { > MyDataReader.Read(); > // Here you can use GetValue, GetString, GetInt32, etc. methods of > the MyDataReader > // to read the various row values > MessageBox.Show(MyDataReader.GetString(0)); // Get first column > value as string > } > finally > { > MyDataReader.Dispose(); > } > } > finally > { > MyEDBCommand.Dispose(); > } > } > |
Wed, Jul 9 2008 2:55 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Chris,
<< As you are using C# you can replace the >> Hah ! My Delphi experience is creeping in there. -- Tim Young Elevate Software www.elevatesoft.com |
Thu, Jul 10 2008 11:16 AM | Permanent Link |
David Loving | Thanks Chris!
I'm learning C#, migrating from Delphi and I really appreciate any discussion of alternative ways to do similar things. Heck, what Tim suggested looked very familar to me! Must be age... |
Thu, Jul 10 2008 3:00 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | David,
<< I'm learning C#, migrating from Delphi and I really appreciate any discussion of alternative ways to do similar things. >> Except for the syntactical stuff, C# and .NET are pretty easy to learn. The framework is very much like the VCL in a lot of ways, except that it uses static class methods for most of the things that we use unit-level procedures and functions. That can be a little confusing at first, but you'll get used to it. -- Tim Young Elevate Software www.elevatesoft.com |
Thu, Jul 10 2008 6:07 PM | Permanent Link |
David Loving | Tim,
I'm actually working with Windows Communication Foundation. My .cs file begins with a public interface followed by a class definition containing implementation code. Hmm... something looks awfully familar to the Object Pascal Language Guide Unit Structure and Syntax... "A unit file begins with a unit heading, which is followed by the interface, implementation, initialization and finalization sections." It seems pretty easy to make the switch. It's knowing all the same functionality is there... but what did Anders call it this time? David L. |
This web page was last updated on Sunday, May 5, 2024 at 10:18 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |