Solved

vs 2010 WinForm, c#, spProducts not found

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SqlServer no dupes 25 35
Adding bootstrap to only Content page and NOT master page 1 13
DataTables + iCheck + pagination Issue 2 23
No Data for DropDown List 2 26
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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