Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Passing DataTable to SP with SQL Server 2008 & .NET 1.1

Posted on 2012-12-27
6
Medium Priority
?
651 Views
Last Modified: 2013-01-16
Hey experts,

we have a SP on SQL Server 2008 that takes a user-defined table type (a 2008 feature). Of course from .NET 4.0 (Visual Studio 2010), I'm able to call it normally passing to it a .NET DataTable.
Now the issue is that I need to call it from a .NET 1.1 application (VS 2003); is there anyway this can be done using some add-in?
0
Comment
Question by:mte01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 38723432
have you tried passing .net datatable . I think that will work

Found a different way to go about doing it. This way uses the System.Data.SqlClient libraries to create a connection to the database, specify the stored procedure name, and then pass a parameter in as a DataTable that serves as the SQL Server user-defined table type.

using (SqlConnection conn = new SqlConnection(connStr)) {
    SqlCommand cmd = conn.CreateCommand();
    cmd.CommandType = System.Data.CommandType.StoredProcedure;
    cmd.CommandText = "dbo.usp_Test";
    cmd.Parameters.AddWithValue("@ids", dt);
    conn.Open();

    using (SqlDataReader sqlReader = cmd.ExecuteReader()) {
        DataTable retTbl = new DataTable();
        retTbl.Load(sqlReader);
    }
refer
http://stackoverflow.com/questions/10624394/sql-server-user-defined-table-type-and-net
0
 
LVL 3

Author Comment

by:mte01
ID: 38723471
>>pratima_mcs

.NET 1.1 does not have AddWithValue; it has an overload of .Add that takes name & value (without dbtype); we tried this, but it errored out at the .Add command with:

Index (zero based) must be greater than or equal to zero and less than the size of the argument list
0
 

Expert Comment

by:mmsi
ID: 38723625
You could try:

SqlParameter param = New SqlParameter();
param = cmd.Parameters.Add("@ids", SqlType.Structured);
param.Value = "your dataTable";

If you receive the message "sqlDBType.Structured" is not part of System.Data.SqlDbType

Then you may need to install a more recent version the the .net framework, because .Structured was added after 2003.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:mte01
ID: 38723639
>>mmsi

This was my point in the 1st place :) I cannot upgrade my current project from 1.1 because it's very large, and I need - if possible - some add-on library that would allow me to do this SP call to SQL Server 2008
0
 
LVL 3

Accepted Solution

by:
mte01 earned 0 total points
ID: 38768696
Apparently, there's no way to do it, but using .NET 3.5 (VS 2008) - it can't be done using .NET 1.1
0
 
LVL 3

Author Closing Comment

by:mte01
ID: 38782013
Came down to it after research
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question