In Focus
Chandigarh Chapter: Developers Day on 29 June 2013
Delhi Chapter Hands On June 22: Limited Seats Register Now
Email :
Password :
Remember me?
Forgot password
Technologies
Monthly Leaders
ASK A QUESTION
C# Programming
Multi-threading
Microsoft Surface
Community Services
Java
.NET General
Office Interoperability
ReFS
Current Affairs
JQuery
Active Directory
Printing
Silverlight 5
Fun and Jokes
JSP
ADO.NET & Database
Project Management
WCF
Job Opportunities
Multimedia, Graphics, Flash
AJAX & Atlas
Remoting
Windows 8
Leadership
PHP
Algorithms & AI
Reporting
Windows Azure
Mac for Windows
Social Networking
Arrays & Collections
Robotics and Hardware
Windows Store Apps
Microsoft Feedback
TypeScript
ASP.NET & Web Development
Security & Cryptography
Workflow Foundation
Open Source Projects
Web Hosting
C# Language
Setup & Deployment
WPF
Operating Systems
Website Management
C# References
Sharepoint
XAML Language
Paid Projects
Windows Azure
CLR & .NET Internals
Speech & Voice Recognition
Site and Forums Feedback
Prizes, Awards, MVP
Windows Phone 7
COM Interoperability
Tablet PC
Announcements
Students & Beginner Projects
Database
Custom Controls
Testing and QA
Author Guidelines
Test Category
Database General
Design and Architecture
Visual Basic .NET
Bugs and Problems
Training & Certification
Oracle
Embedded Development
Visual C++
Forums Feedback
Web Development
SQL
Enterprise Development
Visual Studio 11
Site Feedback & Suggestions
Advertising, Marketing, SEO
SQL Server
Games, DirectX, and XNA
Visual Studio 2010
Site Spams
Android
Products
GDI+ and DirectX
Web Services
Miscellaneous
Cloud Computing
Office 2013
General
Windows Forms
.NET Books
Expression Tools
Products
LINQ
Windows Services
Ask the Author
HTML 5
SharePoint 2013
Migrating to .NET
Cutting-Edge
Career Advice
HTML, JavaScript, CSS
Windows 8
Mobile Development
.NET 5.0
Coffee, Chai Lounge
iPhone, iPad
Forum guidelines
Home
»
General
»
Using SQL stored procedures in C# WinForm appllication
Author
Question
Neven Draskovic
closed
Using SQL stored procedures in C# WinForm appllication
Posted on: 17 Dec 2012
Hey
I'm working on an application that generates certain reports based on data from my clients database. In this database, there are stored procedures whose purpose is to get the necessary data from the database (the queries are very complex and it would be very unpractical to use them as SQLCommands in C#). The problem I'm having is that I can't trigger the stored procedure from my application.
When I try to trigger it directly from code:
sp_AP.CommandText = "EXEC sp_AP"; // I've tried both with and without EXEC command
sp_AP.Parameters.Add(new SqlParameter("@parm1",parm1));
sp_AP.Connection = connection;
SDA.Fill(dtMyDataTable); //SDA is a SqlDataAdapter defined globally
When I execute this code I get the exception "No mapping exists from object type System.Data.DataRow[] to a known managed provider native type.".
When I try to create the new TableAdapter visually in my DataSet, I get the "Invalid object name '#table1'". This part is particularly confusing because when I execute the stored procedure directly on the database it works perfectly.
I've never used stored procedures in my applications before, so please follow any answer with code samples.
Thank you.
Report a Spam
Our Recommended Solutions
Good Practices to Write Stored Procedures in SQL Server
Views & Stored Procedure in SQL Server 2005
Encrypt the stored procedure in sql server
Input Parameters Scenario in SQL Stored Procedure (SQL Server 2005/2008)
Inserting & retrieving images from SQL Server database using stored procedures
Steps to Debug a stored procedure of SQL server 2008 using Visual Studio 2010
Inserting & Retrieving Images from SQL Server Database without using Stored Procedures
How to Use a Custom Entity Class to Stored Procedure Using Linq-To-SQL
Differences Between Procedures and Functions
Writing Managed Stored Procedures using C#
[ + ]
Author
Reply
Satyapriya Nayak
0
0
Re: Using SQL stored procedures in C# WinForm appllication
Posted on: 17 Dec 2012
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; namespace Stored_procedure_to_insert { public partial class _Default : System.Web.UI.Page { string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString; SqlCommand com; SqlDataAdapter sqlda; DataSet ds; protected void btn_insert_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(strConnString); con.Open(); com = new SqlCommand("insert1", con); com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@sid", txtid.Text); com.Parameters.AddWithValue("@sname", txtname.Text); com.Parameters.AddWithValue("@smarks", int.Parse(txtmarks.Text)); com.Parameters.AddWithValue("@saddress", txtaddress.Text); com.Parameters.AddWithValue("@year", txtyear.Text); com.ExecuteNonQuery(); con.Close(); lblmsg.Text = "Data entered successfully!!!"; } } }
If this post helps you mark it as answer
Thanks
Vidya Vrat Agarwal
0
0
Re: Using SQL stored procedures in C# WinForm appllication
Posted on: 17 Dec 2012
You should instead make that table a Global Temporary Table using ##, retry and it should work.
Thanks
Vidya Vrat Agarwal www.MyPassionFor.net http://www.facebook.com/Mypassionfor.net
Neven Draskovic
0
0
Re: Using SQL stored procedures in C# WinForm appllication
Posted on: 17 Dec 2012
Mr. Agarwal, the stored procedures was created by my clients database administrator and I don't have the permission to alter the stored procedures (or the structure of the database for that matter)
Neven Draskovic
0
0
Re: Using SQL stored procedures in C# WinForm appllication
Posted on: 17 Dec 2012
I managed to solve this. The problem wasn't in the stored procedure, but in the parameters I passed. One of the parameters was a value from another DataTable, and I forgot to pass the value (I passed the DataRow). Thanks for your help anyway.
Vidya Vrat Agarwal
0
0
Re: Using SQL stored procedures in C# WinForm appllication
Posted on: 17 Dec 2012
Sor first of all you are trying to access the temporary table from your client's DB, correct?
See this URL,
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/385e6778-a11d-4f90-a378-02e658776bd9/
and if the problem is similar like yours then you may need to do a small prototype at your end(trying # and ##) and if that works, you build a case for your client DBA to change the table names.
Many times it happen that we suggest changes to client schema in order to achieve business functioanlity, as at their design time they can't anticipate all the technical glitches.
Vidya Vrat Agarwal www.MyPassionFor.net http://www.facebook.com/Mypassionfor.net
Quick Reply:
SEARCH ANSWERS
All
C# Programming
Cutting-Edge
Site and Forums Feedback
Miscellaneous
Web Development
Database
Products
Any Word
Exact Word
Our recommended forum posts
How to pass two parameter to reportviewer in C# usingwinform
How to draw with a graphic tablet in VS 2012, .NET 4.5
Export DataGridView content to Excel
stored procedure creation
dropDownList using ajax
Multiple ASP.NET Membership roles in the same Website
Winforms-Combobox, Listbox and Enums - URGENT
post back problem
Help with C#
Primary and Foreign Key in SQL
HOT QUESTIONS
c# writing user input from form to text file using windows a
C# Exception Handling
System.Collection.IList
code is not working
How do i enter a single value from textbox in sqlserver?
how can i locate a webbrowser control
Font Size via C#
How can host WCF Service Application on IIS?
When host to IIS,the styles in CSS can't be applied
C sharp collections....
SPONSORED BY
Get the industry leading .NET Charting component
.NET Charting component with full set of charting and gauge types.