Click here to Skip to main content
12,354,763 members (61,007 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
DAL Code
public void SearchCustomer(int CustomerID)
       {
           try
           {
               conn = new SqlConnection(GlobalVariable.ConnectionString);
               cmd = new SqlCommand();
               cmd.CommandText = "[dbo].[SearchCustomer]";
               cmd.CommandTimeout = 0;
               cmd.CommandType = CommandType.StoredProcedure;
 
               cmd.Connection = conn;
 
               cmd.Parameters.Add("@CustomerID", SqlDbType.Int, 20).Value = CustomerID;
               conn.Open();
               SqlDataReader dr = cmd.ExecuteReader();
               if (dr.HasRows == true)
               {
                   dr.Read();
                   string CustomerName = dr["CustomerName"].ToString();
                   string ShopName = dr["ShopName"].ToString();
                   string ShopAddress = dr["ShopAddress"].ToString();
                   string WorkPhone = dr["WorkPhone"].ToString();
                   string CellPhone = dr["CellPhone"].ToString();
                   string BusinessType = dr["BusinessType"].ToString();
                   dr.Close();
               }
           }
           catch (SqlException)
           {
               throw;
           }
       }

BAL Code
public void SearchCustomer(string CustomerID)
      {
 
          DataAccess.CustomerDLL obj = new DataAccess.CustomerDLL();
 
              obj.SearchCustomer(Convert.ToInt32(CustomerID));
 

      }
Presentation layer
private void txtCustomerID_Leave(object sender, EventArgs e)
        {
            if (txtCustomerID.Text.Length == 0)
            {
                return;
            }
            Business.CustomerBLL obj = new Business.CustomerBLL();
            string CustomerID = txtCustomerID.Text;
            string CustomerName = txtCustomerName.Text;
            string ShopName = txtShopName.Text;
            string ShopAddress = txtShopAddress.Text;
            string WorkPhone = txtWorkPhone.Text;
            string CellPhone = txtCellPhone.Text;
            string BusinessType = cmbBusinessType.Text;
 
            obj.SearchCustomer(CustomerID);
 
        }
Procedure
USE [Diamond]
GO
/****** Object:  StoredProcedure [dbo].[SearchCustomer]    Script Date: 01/27/2013 02:25:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[SearchCustomer]
@CustomeID int
AS
BEGIN
 
    SET NOCOUNT ON;
Select * From CustomerInfo Where (CustomerID  = @CustomeID)
END
Posted 26-Jan-13 10:45am
Edited 26-Jan-13 10:52am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Pretty obvious.

You are passing CustomerID

cmd.Parameters.Add("@CustomerID", SqlDbType.Int, 20).Value = CustomerID;

while stored procedure has a typo and expects CustomeID


ALTER PROCEDURE [dbo].[SearchCustomer]
@CustomeID int
AS

Advise: pay attention to spellchecker hints.
  Permalink  
Comments
Mohsinkh 26-Jan-13 17:05pm
   
Well I correct this mistake. But now there is another problem no record fetch while my leave event fire please help me thanks
Vyacheslav Voronenko 26-Jan-13 17:08pm
   
This is smth unrelated to original question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 26 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100