Solved

vs 2010 WinForm, c#, spProducts not found

Posted on 2013-11-02
2
317 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
[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
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 34

Author Closing Comment

by:Mike Eghtebas
ID: 39619873
Thank you.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

726 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