Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
DAL Code
C#
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
C#
public void SearchCustomer(string CustomerID)
      {

          DataAccess.CustomerDLL obj = new DataAccess.CustomerDLL();

              obj.SearchCustomer(Convert.ToInt32(CustomerID));


      }

Presentation layer
C#
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
SQL
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
Updated 26-Jan-13 10:52am
v2

1 solution

Pretty obvious.

You are passing CustomerID

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

while stored procedure has a typo and expects CustomeID


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


Advise: pay attention to spellchecker hints.
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900