Hi
I am quite new in writing stored procedure. I have created a stored procedure for binding the data from DB. I have to bind data from Specialty table with 2 feilds. For that my stored procedure coding is
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[Pro_Specialty]
@SPID nvarchar(12),
@Specialty nvarchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
select SPID,Specialty from Specialty
END
In .net I have given the coding to bind SPID & Specialty in DropDownList as
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection("user id=sa;password=cast;database=Hello_Dr;server=AUROR A-SERVER;");
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Pro_Specialty";
cmd.Connection = con;
SqlParameter SPID = new SqlParameter("@SPID ", SqlDbType.NVarChar, 12);
SPID.Direction = ParameterDirection.Output;
Specialty_DropDownList.Text = SPID.Value.ToString();
SqlParameter Specialty = new SqlParameter("@Specialty ", SqlDbType.NVarChar, 50);
Specialty.Direction = ParameterDirection.Output;
Specialty_DropDownList.Text = Specialty.Value.ToString();
cmd.Parameters.Add(SPID);
cmd.Parameters.Add(Specialty);
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
da.Fill(ds);
Specialty_DropDownList.DataValueField = "SPID";
Specialty_DropDownList.DataTextField = "Specialty";
Specialty_DropDownList.DataSource = ds;
Specialty_DropDownList.DataBind();
con.Close();
}
But while running I am receiving the error as
Error 2 The name 'sql' does not exist in the current context E:\suganya\Suganya_Hello_Dr\Search.aspx.cs 59 49 E:\suganya\Suganya_Hello_Dr\