Click here to Skip to main content
15,299,443 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This my Procedure

SQL
CREATE PROCEDURE [dbo].[Search Customer]       
(
 @cusCode varchar(10),
 @Status int
 )
AS
BEGIN

	IF  (@Status = 0)
	
	Select * from tblCustomer where cusCode=@cusCode
	

END



Asp Code

C#
String procedureName;
           CommandType cmdType;
           List<SqlParameter> parameters = new List<SqlParameter>();

           //setting procedure properties
           procedureName = "Search Customer";
           cmdType = CommandType.StoredProcedure;


           parameters.Add(new SqlParameter("@cusCode", SqlDbType.VarChar, (30)));//0
           parameters.Add(new SqlParameter("@Status", SqlDbType.Int));//1

           parameters[0].Value = txtcusCode.Text;//0;
           parameters[1].Value = 0;

           Boolean status1 = Common.executeProcedure(procedureName, cmdType, parameters);

           String CusCode =txtcusCode.Text;
           if (status1 == true)
           {
               if (CusCode == "001")
                  {
                  DropDown_Customer.SelectedValue = cusDataSet.Rows[0][0].ToString();
                  }

 else
        {

        DropDown_Customer.SelectedValue = cusDataSet.Rows[0][0].ToString();
        dropdowncutomer.SelectedItem.Text = cusDataSet.Rows[0][1].ToString();
        txtcustomerName.Text = cusDataSet.Rows[0][1].ToString();
         


          }
           }



my asp code not working ??? anyone can help me to slove this??

What I have tried:

Quote:
String strConnString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Search Customer";
cmd.Connection = con;
try
{
con.Open();
DropDown_Customer.DataSource = cmd.ExecuteReader();
DropDown_Customer.DataTextField = "cusName";
DropDown_Customer.DataValueField = "cusCode";
DropDown_Customer.DataBind();
DropDown_Customer.Items.Insert(0, new ListItem("Select"));
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
con.Dispose();
}
Posted
Updated 23-Nov-16 0:25am
Comments
Suvendu Shekhar Giri 23-Nov-16 1:29am
   
"not working" means? giving any error?

Sugestion: Change SP name from "Search Customer" to "SearchCustomer".
F-ES Sitecore 23-Nov-16 5:03am
   
Or try square brackets

procedureName = "[Search Customer]";

Hi Guys

Check this useful resources to Select SQL server stored procedures using ASP.NET.I think it will helpful for you.

Select Insert Update and Delete using Stored Procedure in ASP.NET MVC4[^]

ASP.NET Stored Procedures[^]
   
v2
C#
String strConnString = ConfigurationManager.ConnectionStrings["AntronERP_DBConnectionString2"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnString);
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "Search Customer";
            cmd.Parameters.Add("@cusCode", SqlDbType.NChar).Value = txtcusCode.Text.Trim();
            cmd.Parameters.Add("@Status", SqlDbType.Int).Value = 0;
            cmd.Connection = con;
            try
            {
                con.Open();
                DropDown_Customer.DataSource = cmd.ExecuteReader();
                DropDown_Customer.DataTextField = "cusName";
                DropDown_Customer.DataValueField = "cusCode";
                DropDown_Customer.DataBind();
                //DropDown_Customer.Items.Insert(0, new ListItem("Select"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
                con.Dispose();
            }
   

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