I am getting this error..
"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."
I have written this procedure..
///////////////////////////////////////////////////////////////////////////////
alter procedure myprocedure
(
@flag varchar(1),
@id varchar(25),
@amt decimal(10,2)
)
as
begin
if @flag='D'
begin
declare @balance decimal(10,2)
set @balance=(select balance from mytransaction where emailid=@id);
if (@balance IS NULL)
begin
set @balance=@amt;
end
else
begin
set @balance=@balance+@amt;
end
insert into mytransaction values(@id,@balance,GETDATE(),'DEPOSIT',@amt)
end
else if @flag='W'
begin
declare @chkbalance decimal(10,2)
set @chkbalance=(select balance from mytransaction where emailid=@id);
if (@amt>@chkbalance)
begin
SELECT 'Amount cannot be greater than balance.' AS 'Result'
end
else
begin
declare @wbalance decimal(10,2)
set @wbalance=(select balance from mytransaction where emailid=@id);
set @wbalance=@wbalance-@amt;
insert into mytransaction values(@id,@wbalance,GETDATE(),'WITHDRAW',@amt)
SELECT 'You have withdraw ammount of -->' + str(@amt) AS 'Result'
end
end
end
//////////////////////////////////////////////////////////////////////////////
and have written follwing line of code in code file
///////////////////////////////////////////////////////////////////////////////
protected void btntransaction_Click(object sender, EventArgs e)
{
cn.Open();
if (rdbwithdraw.Checked == true)
{
cmd = new SqlCommand("myprocedure", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@flag", SqlDbType.VarChar).Value = "W";
cmd.Parameters.AddWithValue("@id", SqlDbType.VarChar).Value = hdnname.Value;
cmd.Parameters.AddWithValue("@amt",SqlDbType.Decimal).Value = txtamt.Text;
da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt != null && dt.Rows.Count > 0)
Response.Write(dt.Rows[0]["Result"].ToString());
}
else
{
cmd = new SqlCommand("myprocedure", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@flag", SqlDbType.VarChar).Value = "D";
cmd.Parameters.AddWithValue("@id", SqlDbType.VarChar).Value = hdnname.Value;
cmd.Parameters.AddWithValue("@amt", SqlDbType.Decimal).Value = txtamt.Text;
cmd.ExecuteNonQuery();
Response.Write("You have deposited ammount of -->" + txtamt.Text);
txtamt.Text = "";
}
cn.Close();
}