Solved

vs 2010 WinForm, c#, spProducts not found

Posted on 2013-11-02
2
318 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

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