1
Reply

How to fetch data from database using label control i used sql server

sagar Bhosale

sagar Bhosale

13y
6.3k
0
Reply

    My stored procedure

    USE [india89_survey]
    GO
    /****** Object:  StoredProcedure [dbo].[FetchCoverReport]    Script Date: 05/20/2011 10:05:15 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author: <Author,,Name>
    -- Create date: <Create Date,,>
    -- Description: <Description,,>
    -- =============================================
    ALTER PROCEDURE [dbo].[FetchCoverReport]
    -- Add the parameters for the stored procedure here
    @CoverReportId int
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    if (@CoverReportId is not null)
    BEGIN
        -- Insert statements for procedure here
    SELECT projectId from CoverReport
    where CoverReportId=@CoverReportId  
    END
     
    END

    CoverReportContext.cs

    public DataTable fetchCoverReport(int coverReportId) {
    DataTable ds = new DataTable();
    try {
    this.OpenConn();
    SqlCommand command = new SqlCommand();
    command.Connection = this.conn;
    command.CommandType = CommandType.StoredProcedure;
    command.CommandText = "FetchCoverReport";
    command.Parameters.AddWithValue("@coverReport",coverReportId);
    //command.Parameters.AddWithValue("@projectId",projectId);
    //command.Parameters.AddWithValue("@weekStartDate", weekStartDate);
    //command.Parameters.AddWithValue("@weekEndDate", weekEndDate);
    using (SqlDataAdapter adapter = new SqlDataAdapter(command)) {
    adapter.Fill(ds);
    }
    return ds;
    } catch (Exception ex) {
    throw ex;
    } finally {
    this.CloseConn();
    }
    }
    CoverReport.aspx.cs
    protected void btnFetchCoverReport_Click(object sender, EventArgs e) {
    try {

    DataTable ds = new CoverReportContext(ConfigurationManager.ConnectionStrings["survey_connection"].ToString()).
    fetchCoverReport(int.Parse(Request.QueryString["coverReportId"].Trim()));

    Label1.Text =ds.Rows[0]["projectId"].ToString();

    } catch (Exception ex) {
    throw ex;
    }
    }
    But i got error that  = 

    Object reference not set to an instance of an object.

    Please help me Thanks