Hi
I have to bind the DropDownList box with ID field hidden using SQLDataAdapter.
For that I have given the coding as
protected void Page_Load(object sender, EventArgs e)
{
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);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Specialty_DropDownList.DataValueField = "SPID";
Specialty_DropDownList.DataTextField = "Specialty";
Specialty_DropDownList.DataSource = ds;
Specialty_DropDownList.DataBind();
con.Close();
}
}
I have created the stored procedure in sql server 2005 as
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE Pro_Specialty
@SPID nvarchar(12)output,
@Specialty nvarchar(50)output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
-- Insert statements for procedure here
select @SPID=SPID,@Specialty=Specialty from Specialty
END
But if I run, I get the error
Object reference not set to an instance of the object.