Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB General » View Thread |
Messages 1 to 5 of 5 total |
Parameters to Stored Procedure |
Thu, Feb 14 2008 6:27 AM | Permanent Link |
Robin Joseph | Tim
Using VS2008, EDB 1.07 B3 I have created a Stored procedure with one integer parameter - I have tested this and it works ok in EDB Manager (Unicode) In C# Code I do the following:- EDBCommand DataCommand = new EDBCommand(); DataCommand.CommandText = "Test Proc 2"; DataCommand.CommandType = CommandType.StoredProcedure; DataCommand.Connection = new EDBConnection(EDBConnStr); EDBParameter Param = new EDBParameter(); Param.ParameterName = "RecordID"; Param.DbType = DbType.Int32; Param.ProviderType = EDBType.Integer; Param.Direction = ParameterDirection.Input; Param.Value = (int) 1001; DataCommand.Parameters.Add(Param); EDBDataAdapter DataAdapter = new EDBDataAdapter(DataCommand); DataTable EDBDataTable = new DataTable("EDB Test Table"); DataAdapter.Fill(EDBDataTable); The EDBConnStr, ParameterName and Value are all correct and should return one row. When I run the above code 0 rows are returned. Am I doing something incorrect or is there a bug? regards Robin |
Fri, Feb 15 2008 6:28 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Robin,
<< I have created a Stored procedure with one integer parameter - I have tested this and it works ok in EDB Manager (Unicode) >> You should be able to use this code instead: EDBCommand DataCommand = new EDBCommand(); DataCommand.CommandText = "Test Proc 2"; DataCommand.CommandType = CommandType.StoredProcedure; DataCommand.Connection = new EDBConnection(EDBConnStr); DataCommand.Prepare; DataCommand.Parameters["RecordID"] = (int) 1001; EDBDataAdapter DataAdapter = new EDBDataAdapter(DataCommand); DataTable EDBDataTable = new DataTable("EDB Test Table"); DataAdapter.Fill(EDBDataTable); You must call the Prepare method first, as it will pre-populate all of the parameters. With the code you were using before, the command was getting prepared *after* you added the parameter, thus clearing it out and replacing it with a NULL parameter that ElevateDB automatically created. -- Tim Young Elevate Software www.elevatesoft.com |
Fri, Feb 15 2008 7:55 AM | Permanent Link |
Robin Joseph | Tim,
Thank you again. The code needed slight modification DataCommand.Connection.Open(); DataCommand.Prepare(); DataCommand.Parameters["RecordID"].Value = (int)1001; Do I need to DataCommand.Close(); after DataAdapter.Fill(EDBDataTable); or will it automatically close? Regards Robin "Tim Young [Elevate Software]" <timyoung@elevatesoft.com> wrote: Robin, << I have created a Stored procedure with one integer parameter - I have tested this and it works ok in EDB Manager (Unicode) >> You should be able to use this code instead: EDBCommand DataCommand = new EDBCommand(); DataCommand.CommandText = "Test Proc 2"; DataCommand.CommandType = CommandType.StoredProcedure; DataCommand.Connection = new EDBConnection(EDBConnStr); DataCommand.Prepare; DataCommand.Parameters["RecordID"] = (int) 1001; EDBDataAdapter DataAdapter = new EDBDataAdapter(DataCommand); DataTable EDBDataTable = new DataTable("EDB Test Table"); DataAdapter.Fill(EDBDataTable); You must call the Prepare method first, as it will pre-populate all of the parameters. With the code you were using before, the command was getting prepared *after* you added the parameter, thus clearing it out and replacing it with a NULL parameter that ElevateDB automatically created. -- Tim Young Elevate Software www.elevatesoft.com |
Fri, Feb 15 2008 2:58 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Robin,
<< Thank you again. The code needed slight modification >> Whoops, sorry - I forgot that the connection wasn't open yet. I'm thinking that I should put in code to have any EDBCommand actions that need the connection open to automatically open the connection. << Do I need to DataCommand.Close(); after DataAdapter.Fill(EDBDataTable); or will it automatically close? >> The DataAdapter will only automatically close the connection if the DataAdapter opened the connection, otherwise the DataAdapter will simply leave it open. -- Tim Young Elevate Software www.elevatesoft.com |
Fri, Feb 15 2008 5:19 PM | Permanent Link |
Robin Joseph | Tim
<< I'm thinking << that I should put in code to have any EDBCommand actions that need the << connection open to automatically open the connection. It might make it easier only from the point of view of not having to remember to close the connection after use. From my point of view, this would only be a minor enhancement. Thanks Robin |
This web page was last updated on Monday, April 29, 2024 at 05:23 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |