Click here to Skip to main content
Sign Up to vote bad
good
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:45
Edited 26 Jan '13 - 10:52


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
 

ALTER PROCEDURE [dbo].[SearchCustomer]
@CustomeID int
AS
 
Advise: pay attention to spellchecker hints.
  Permalink  
Comments
Mohsinkh - 26 Jan '13 - 17:05
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:08
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
Your Filters
Interested
Ignored
     
0 OriginalGriff 206
1 Richard MacCutchan 145
2 Tadit Dash 140
3 Santhosh G_ 125
4 Volynsky Alex 105
0 Sergey Alexandrovich Kryukov 10,264
1 OriginalGriff 7,957
2 CPallini 4,201
3 Rohan Leuva 3,522
4 Maciej Los 3,155


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 26 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid