Solved

vs 2010 WinForm, c#, spProducts not found

Posted on 2013-11-02
2
313 Views
Last Modified: 2013-11-03
At line 45 da.Fill(ds); the attached code errors: Cannot find the stored procedure

Using straight Select * From Products, this code works fine (meaning there is no connection issue to the database) and the store procedure exists in the database (it has been tested in SSMS).

Question: Why this could cannot find spProducts?

Thank you.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;

namespace ado01_Connection
{
    public partial class Form10 : Form
    {
        public Form10()
        {
            InitializeComponent();
        }

        private void Form10_Load(object sender, EventArgs e)
        {
            //string cs = ConfigurationManager.ConnectionStrings["csDatabase"].ConnectionString;
            //SqlConnection con = new SqlConnection(cs);
            
            //using (con)
            //{
            //    SqlDataAdapter da = new SqlDataAdapter("SELECT [CategoryName],[Description],[Picture] FROM [Northwind].[dbo].[Categories];", con);
            //    DataSet ds = new DataSet();
            //    da.Fill(ds);
            //    gwCategory.DataSource = ds.Tables[0];
            //}
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string cs = ConfigurationManager.ConnectionStrings["csDatabase"].ConnectionString;
            SqlConnection con = new SqlConnection(cs);
            DataSet ds = new DataSet();
            using (con)
            {
                SqlDataAdapter da = new SqlDataAdapter("spProducts;", con);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                da.SelectCommand.Parameters.AddWithValue("@CategoryID", "5");//txtCategoryId.Text);
                da.Fill(ds);
                gwCategory.DataSource = ds.Tables[0];
            }
        }
        }
    }

Open in new window

0
Comment
Question by:Mike Eghtebas
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39619630
Not sure if that will be the final solution but start with removing the semicolon after the stored procedure name.
SqlDataAdapter da = new SqlDataAdapter("spProducts;", con);

Open in new window

probably just need:
SqlDataAdapter da = new SqlDataAdapter("spProducts", con);

Open in new window

0
 
LVL 33

Author Closing Comment

by:Mike Eghtebas
ID: 39619873
Thank you.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now