hi
this is Order_users table indata base:
Id
|
Name
|
Code
|
Type
|
Date
|
1
|
Waterfall
|
1111
|
Film
|
2016-2-03
|
2
|
Waterfall
|
1111
|
Animation
|
2016-2-03
|
3
|
Waterfall
|
1111
|
Serial
|
2016-203
|
and I bind gridview from this table...
I want when click on button it save all row of gridview in other table in database so below are code:
protected void LBsabt_Click(object sender, EventArgs e)
{
int data = Convert.ToInt32(Request.QueryString["PeygiriCode"].ToString());
using (SqlConnection conn = General.GetConnection())
{
using (SqlCommand _cmd = General.GetCommand("OrderC_Insert", conn))
{
conn.Open();
foreach (GridViewRow row in gvOrders.Rows)
{
_cmd.Parameters.Clear();
string OrderType = (row.FindControl("LblOrderType") as Label).Text.Trim();
string PName = (row.FindControl("LblName") as Label).Text.Trim();
_cmd.Parameters.AddWithValue("@Name", PName);
_cmd.Parameters.AddWithValue("@Code", data);
_cmd.Parameters.AddWithValue("@Type", OrderType);
_cmd.ExecuteNonQuery();
}
}
}
}
and SP:
GO
ALTER procedure [dbo].[OrderC_Insert]
@Name nvarchar(100)
,@Code nvarchar(10)
,@Type nvarchar(50)
AS
BEGIN
Declare @date date set @date =(select date from Order_Users where code=@code )
INSERT INTO Order_Confirm
(Name,Code,Type ,PostCode,date )
VALUES
(@Name,@Code,@Type,@date)
END
but when I click button below error happen:
Server Error in '/' Application.
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
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.Data.SqlClient.SqlException: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
Source Error:
Line 134: //_cmd.Parameters.AddWithValue("@PriceP", PriceP);
Line 135:
Line 136: _cmd.ExecuteNonQuery();
Line 137:
Line 138: }
|
this error happen becuse of below code:
Declare @date date set @date =(select date from Order_Users where code=@code )
becuse I have same code in table...
how I can solve this problem?
Best regards
neda