Is there some way to pass a table-valued parameter to a stored procedure in SQL Server via classic ADO?
Classic ADO is COM and OLE and the SQL Native Client supports Table Valued Parameters over OleDB, see Table-Valued Parameters (OLE DB). One would have to get its hand dirty and code straight to the OleDB interfaces (in C/C++).
Also TVPs are only in SQL 2008, so you won't be able to use them in SQL 2005.
BTW, for completness here is the Table Valued Parameters (ODBC) reference, for the ODBC nostalgics out there...
I thought they were new in 2008?
Anyway, I think the answer is going to be no, I doubt there's a DataTypeEnum value that you'll be able to bend to your needs.
So if I may suggest an alternative, I guess what you want to do is pass some sort of structured data into the stored procedure. I have done this before in ADO using XML:
define the parameter in the stored proc as type xml
define the parameter in ADO as type adLongVarChar with a length = len(xml) + 1
I know it's not what you wanted, but it's a method that works
Related
I am trying to display T-SQL of stored procedure in my delphi application.
I have no idea whether it is possible using ADO or Firedac components. I am able to get list of stored procedures using firedac but not sql.
Need to be pointed to the right direction so that i can add this feature in my application.
I have a pass-through query (for SQL Server) in Access which works with explicit values. For a non-pass-though query, I just use the visual editor to create parameters for the affected columns.
Is it possible to do the equivalent with a pass-through query or must I assemble the query with VBA (as mentioned in another post)?
TIA,
Paolo
Unfortunately, you cannot. It would be once possible with ODBCDirect workspace but that was removed since Access 2010. Therefore, for pass-through queries, you would have to concatenate SQL.
A possible alternative is to use ADO which allow you to create parameters and thus construct a command and execute it. Note that your project doesn't have to be limited to only DAO; you can use both DAO and ADO, leveraging what works best for your requirements.
I am calling a report which is linked to a stored procedure from my Access 2010 .adp file
For example:
DoCmd.OpenReport "r_my_report", acPreview, , "xxx=" & Chr(34) & xxx & Chr(34)
Is it possible to echo the where clause or the filter parameter and do some logic on it in the stored procedure? Do these parameters come into the stored procedure in a way that you can use them, or does access just feed them directly to the SQL engine behind the scenes? Can I even just echo or log the actual query that is executed?
I am climbing the learning curve on this, so thanks in advance for your help.
An Access .adp provides a fairly direct interface to SQL server, the stored procedure you see in the adp is an actual stored procedure in SQL Server database.
You have a report based on a stored procedure with a filter, what is probably happening is the stored procedure is executed with it's parameters, the data set is then passed back to the client where it is then filtered by the client.
If you'd used a view instead of a stored procedure then the query would probably converted and passed to the sql server, the server's optimiser would then have worked out a plan to optimise it's execution including the fields from the where clause.
To find out what is happening on the server use the SQL Server Profiler, this will give you a list of all queries as the run against the server along with some statistics. You may find access is being cleverer than you expect.
I have a stored proc that I use to create some customized lists. I'm trying to create it as an SSRS report, but it's running into a sticking point where it chokes trying to deal with the User Defined Table Type parameters.
Am I just screwed?
As an aside, it does work when you call it with a sql exec statement.
Thanks,
AFAIK there is currently no "native" way to pass table-valued parameters from SSRS to a stored procedure. However it is still can be done in a sort of a hackish way:Using Table-Valued Parameters With SQL Server Reporting Services or Passing Multivalued Parameters in SQL Server 2008.
My program has code that saves attachments, I want these attachments to be transferred to the database, and I am going to use a stored procedure to accomplish this.
I need to know what is the #param type to accept an array of binary files?
finally once I have this array, how to I insert this data into a SQL table?
I guess I am looking at using a byte[] for 1 file, but how do I pass from C# or .net a collection of byte arrays to the SP, and what should the param type be to accept this array of byte[]
Updated
Need a solution that will work in 2005 and 2008.
Update
I've decided to scrap the idea of having 1 large SP to process everything. Instead I am going to have smaller SPs, then handle the transaction in .net.
Do you think this would be a better solution, to handle the transaction in .net data objects?
If you were needing only to pass an array of values, I would suggest to format them as XML and pass them as the SQL xml datatype. You can perform select from XML with SQL just as easily as from a table.
It may also technically work if you pass binary data in XML, but I'm not sure it will be a good solution. Anyway, it is an option.
For SQL Server 2008, you can use the table-valued parameter feature.
This allows you to define a parameter of a table type, and then supply values to that parameter as a DataTable from your C# code.
See these blog posts and articles for more information:
SQL Server 2008: Table-valued parameters
Using Table-Valued Parameters in SQL Server 2008
This is a new feature of SQL Server 2008, so you won't have this in SQL Server 2000 or 2005.
UPDATE: if you need to support SQL Server 2005 as well, check out Erland Sommarskog's excellent article Arrays and Lists in SQL Server 2005. It offers a few ideas on how to accomplish this in 2005.
Marc
See Arrays and Lists in SQL 2005. This article aggregates pretty much every technique there is out there and discusses the advantages and problems with each approach.
I decided to create just one SP, and call it multiple times, one for each file I need uploaded, and keep the transaction managed in C# code.