Click here to Skip to main content
Rate this: bad
good
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 at 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 at 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
0 OriginalGriff 540
1 Sergey Alexandrovich Kryukov 432
2 Yogesh Kumar Tyagi 384
3 Prakriti Goyal 280
4 Maciej Los 205
0 OriginalGriff 6,632
1 Sergey Alexandrovich Kryukov 5,404
2 Maciej Los 3,474
3 Peter Leow 3,299
4 DamithSL 2,495


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 26 Jan 2013
Copyright © CodeProject, 1999-2014
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