Home > Forum > ASP.NET > am getting error while i fetch the data from sql server 2005

am getting error while i fetch the data from sql server 2005

by celv   on Oct 28, 2014   Category: ASP.NET  |  Views: 885    |  Points: 5   |  Bronze 
  Reply
My Procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[atendancepresent] ( @Id int, @Name varchar(50) , @Status varchar(50) , @Section varchar(50), @Date varchar(50), @intime datetime, @outtime datetime, @action varchar(50),@pIntErrDescOut int output ) AS BEGIN if(@action='select') BEGIN
SELECT name, section, id AS idd FROM EmpReg WHERE id NOT IN (SELECT id FROM aten WHERE date =@Date) END ELSE if(@action='insert') BEGIN
INSERT INTO absentdays(id,name,section,date,status)
VALUES (@id,
@name,
@section,
@date,
@status) END



ELSE if(@action='update') BEGIN
UPDATE aten
SET outtime=@outtime WHERE id=@id and name=@name and date=@date END END



My coding

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ setda();
}
}

private void setda()
{
try
{
con = new SqlConnection(s);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText= "atendancepresent";
cmd.Parameters.Add(new SqlParameter("@action", SqlDbType.VarChar, 50));
cmd.Parameters["@action"].Value = "select";
cmd.Parameters.Add("@pIntErrDescOut", SqlDbType.Int).Direction = ParameterDirection.Output;
SqlDataAdapter SqlAda = new SqlDataAdapter();
SqlAda = new SqlDataAdapter(cmd);
ds = new DataSet();
SqlAda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch
{
throw;
}
finally
{
cmd.Dispose();
con.Close();
con.Dispose();
}
}


My data in table


Name section id
Celv Owner 2
Subramanian Owner 3


my error is

Server Error in '/bramandam site' Application.

Fill: SelectCommand.Connection property has not been initialized.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized.

Source Error:


Line 62: catch
Line 63: {
Line 64: throw;
Line 65: }
Line 66: finally

Source File: d:\selvi\bramandam site\ExitEmployee.aspx.cs Line: 64

Stack Trace:


[InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized.]
System.Data.Common.DbDataAdapter.GetConnection3(DbDataAdapter adapter, IDbCommand command, String method) +4833854
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +81
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +287
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet) +94
ExitEmployee.setda() in d:\selvi\bramandam site\ExitEmployee.aspx.cs:64
ExitEmployee.Page_Load(Object sender, EventArgs e) in d:\selvi\bramandam site\ExitEmployee.aspx.cs:33
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971

Bookmark and Share:
 
  User Reply  | Ask a question  |   Reply 


  No response found, be the first to answer this question.


Recent Post

Latest Posts

1 3D model and 2D View New! Forum