alter PROCEDURE [dbo].[sp_transaction_order_Import]
-- CHANNEL_EBAY_TRANSACTIONS
@Id UniqueIdentifier,
@CreatedDate DateTime,
@ProductId UniqueIdentifier,
@ItemID bigint,
@QuantityPurchased int,
@TransactionPrice Decimal(12,2),
@CurrencyID Int,
@UserID VarChar(50)=null,
@SellerID Int,
@ListingType Int,
@TransactionStatus Int,
@TransactionPlatform smallint ,
--CHANNEL_EBAY_TRANSACTIONS_USER
@EIASToken VarChar(56)=null,
@Email VarChar(100)=null,
@FeedbackRatingStar Int,
@IDVerified Bit,
@NewUser Bit,
@RegistrationDate DateTime,
@Site Int,
@Status Int,
@UniqueNegativeFeedbackCount Int,
@UniquePositiveFeedbackCount Int,
@UserIDChanged Bit,
@UserIDLastChanged DateTime,
@eBayGoodStanding Bit,
--CHANNEL_EBAY_TRANSACTIONS_BUYER
@AddressID BigInt,
@AddressOwner Int,
@AddressRecordType Int,
@AddressStatus Int,
@CityName VarChar(50)=null,
@CompanyName VarChar(50)=null,
@Country Int,
@CountryName VarChar(50)=null,
@ExternalAddressID VarChar(50)=null,
@InternationalName VarChar(50)=null,
@InternationalStateAndCity VarChar(50)=null,
@InternationalStreet VarChar(50)=null,
@Name VarChar(50)=null,
@Phone VarChar(50)=null,
@PostalCode VarChar(50)=null,
@StateOrProvince VarChar(50)=null,
@Street VarChar(50)=null,
@Street1 VarChar(50)=null,
@Street2 VarChar(50)=null,
--CHANNEL_EBAY_TRANSACTIONS_DETAIL
@BestOfferSale Bit,
@BuyerMessage VarChar(512)=null,
@QuantitySold Int,
@TransactionID BigInt,
@FeedbackScore BigInt,
@StartTime DateTime,
@EndTime DateTime,
@BuyItNowPrice Decimal(12,2),
@StartPrice Decimal(12,2),
@CategoryID BigInt,
@RelistedItemID BigInt,
@Title VarChar(55)=null,
--CHANNEL_EBAY_TRANSACTIONS_SHIPPING
@ShippingInsuranceCost Decimal(12,2),
@ShippingService Int,
@ShippingServiceCost Decimal(12,2),
@ShippingServicePriority Int,
--CHANNEL_EBAY_TRANSACTIONS_DETAIL
@DetailStatus Int
AS
BEGIN
SET NOCOUNT ON;
--select is exist
select 1 from CHANNEL_EBAY_TRANSACTIONS_VIEW a
join CHANNEL_EBAY_TRANSACTIONS_BUYER b on a.id = b.id
join CHANNEL_EBAY_TRANSACTIONS_DETAIL d on a.id = d.id
join CHANNEL_EBAY_TRANSACTIONS_SHIPPING s on a.id = s.id
join CHANNEL_EBAY_TRANSACTIONS_USER u on a.id = u.id
where a.itemid = @itemid
IF @@Rowcount = 1
RETURN -99 --begin tran
BEGIN TRANSACTION
--insert CHANNEL_EBAY_TRANSACTIONS
INSERT INTO CHANNEL_EBAY_TRANSACTIONS(Id, CreatedDate, ProductId, ItemID, QuantityPurchased, TransactionPrice,
CurrencyID, UserID, SellerID, ListingType, TransactionStatus, TransactionPlatform)
VALUES (@Id, @CreatedDate, @ProductId, @ItemID, @QuantityPurchased, @TransactionPrice,@CurrencyID,
@UserID, @SellerID, @ListingType, @TransactionStatus, @TransactionPlatform)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -1
END
--insert CHANNEL_EBAY_TRANSACTIONS_BUYER
INSERT INTO CHANNEL_EBAY_TRANSACTIONS_BUYER(Id, AddressID, AddressOwner, AddressRecordType, AddressStatus,
CityName, CompanyName, Country, CountryName, ExternalAddressID, InternationalName,
InternationalStateAndCity, InternationalStreet, Name, Phone, PostalCode,
StateOrProvince, Street, Street1, Street2)
VALUES (@Id, @AddressID, @AddressOwner, @AddressRecordType, @AddressStatus, @CityName, @CompanyName,
@Country, @CountryName, @ExternalAddressID, @InternationalName, @InternationalStateAndCity,
@InternationalStreet, @Name, @Phone, @PostalCode, @StateOrProvince, @Street, @Street1, @Street2)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -2
END
--insert CHANNEL_EBAY_TRANSACTIONS_DETAIL
INSERT INTO CHANNEL_EBAY_TRANSACTIONS_DETAIL(Id, BestOfferSale, BuyerMessage, QuantitySold, TransactionID,
FeedbackScore, StartTime, EndTime, BuyItNowPrice, StartPrice, CategoryID,RelistedItemID, Title)
VALUES (@Id, @BestOfferSale, @BuyerMessage, @QuantitySold,@TransactionID, @FeedbackScore, @StartTime,
@EndTime, @BuyItNowPrice, @StartPrice,@CategoryID, @RelistedItemID, @Title)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -3
END
--insert CHANNEL_EBAY_TRANSACTIONS_SHIPPING
INSERT INTO CHANNEL_EBAY_TRANSACTIONS_SHIPPING(Id, ShippingInsuranceCost, currencyID, ShippingService, ShippingServiceCost, ShippingServicePriority)
VALUES (@Id, @ShippingInsuranceCost, @currencyID, @ShippingService, @ShippingServiceCost, @ShippingServicePriority)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -4
END
--insert CHANNEL_EBAY_TRANSACTIONS_USER
INSERT INTO CHANNEL_EBAY_TRANSACTIONS_USER(Id, EIASToken, Email, FeedbackRatingStar, FeedbackScore, IDVerified,
NewUser, RegistrationDate, Site, Status, UniqueNegativeFeedbackCount,
UniquePositiveFeedbackCount, UserID, UserIDChanged, UserIDLastChanged, eBayGoodStanding)
VALUES (@Id, @EIASToken, @Email, @FeedbackRatingStar, @FeedbackScore, @IDVerified, @NewUser,
@RegistrationDate, @Site, @Status, @UniqueNegativeFeedbackCount, @UniquePositiveFeedbackCount,
@UserID, @UserIDChanged, @UserIDLastChanged, @eBayGoodStanding)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -5
END
--insert CHANNEL_EBAY_TRANSACTIONS_DETAIL
INSERT INTO Channel_Ebay_Transaction_PayRecord(Id,ItemID,TransactionID,CreatedDate,UserID,[Status])
Values(@Id,@ItemID,@TransactionID,@CreatedDate,@UserID,@DetailStatus)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -6
END
--commit
COMMIT
return 1
END
调用后一直返回-1,这是什么问题啊?
c# 怎么调用,请给出调用代码。
-- CHANNEL_EBAY_TRANSACTIONS
@Id UniqueIdentifier,
@CreatedDate DateTime,
@ProductId UniqueIdentifier,
@ItemID bigint,
@QuantityPurchased int,
@TransactionPrice Decimal(12,2),
@CurrencyID Int,
@UserID VarChar(50)=null,
@SellerID Int,
@ListingType Int,
@TransactionStatus Int,
@TransactionPlatform smallint ,
--CHANNEL_EBAY_TRANSACTIONS_USER
@EIASToken VarChar(56)=null,
@Email VarChar(100)=null,
@FeedbackRatingStar Int,
@IDVerified Bit,
@NewUser Bit,
@RegistrationDate DateTime,
@Site Int,
@Status Int,
@UniqueNegativeFeedbackCount Int,
@UniquePositiveFeedbackCount Int,
@UserIDChanged Bit,
@UserIDLastChanged DateTime,
@eBayGoodStanding Bit,
--CHANNEL_EBAY_TRANSACTIONS_BUYER
@AddressID BigInt,
@AddressOwner Int,
@AddressRecordType Int,
@AddressStatus Int,
@CityName VarChar(50)=null,
@CompanyName VarChar(50)=null,
@Country Int,
@CountryName VarChar(50)=null,
@ExternalAddressID VarChar(50)=null,
@InternationalName VarChar(50)=null,
@InternationalStateAndCity VarChar(50)=null,
@InternationalStreet VarChar(50)=null,
@Name VarChar(50)=null,
@Phone VarChar(50)=null,
@PostalCode VarChar(50)=null,
@StateOrProvince VarChar(50)=null,
@Street VarChar(50)=null,
@Street1 VarChar(50)=null,
@Street2 VarChar(50)=null,
--CHANNEL_EBAY_TRANSACTIONS_DETAIL
@BestOfferSale Bit,
@BuyerMessage VarChar(512)=null,
@QuantitySold Int,
@TransactionID BigInt,
@FeedbackScore BigInt,
@StartTime DateTime,
@EndTime DateTime,
@BuyItNowPrice Decimal(12,2),
@StartPrice Decimal(12,2),
@CategoryID BigInt,
@RelistedItemID BigInt,
@Title VarChar(55)=null,
--CHANNEL_EBAY_TRANSACTIONS_SHIPPING
@ShippingInsuranceCost Decimal(12,2),
@ShippingService Int,
@ShippingServiceCost Decimal(12,2),
@ShippingServicePriority Int,
--CHANNEL_EBAY_TRANSACTIONS_DETAIL
@DetailStatus Int
AS
BEGIN
SET NOCOUNT ON;
--select is exist
select 1 from CHANNEL_EBAY_TRANSACTIONS_VIEW a
join CHANNEL_EBAY_TRANSACTIONS_BUYER b on a.id = b.id
join CHANNEL_EBAY_TRANSACTIONS_DETAIL d on a.id = d.id
join CHANNEL_EBAY_TRANSACTIONS_SHIPPING s on a.id = s.id
join CHANNEL_EBAY_TRANSACTIONS_USER u on a.id = u.id
where a.itemid = @itemid
IF @@Rowcount = 1
RETURN -99 --begin tran
BEGIN TRANSACTION
--insert CHANNEL_EBAY_TRANSACTIONS
INSERT INTO CHANNEL_EBAY_TRANSACTIONS(Id, CreatedDate, ProductId, ItemID, QuantityPurchased, TransactionPrice,
CurrencyID, UserID, SellerID, ListingType, TransactionStatus, TransactionPlatform)
VALUES (@Id, @CreatedDate, @ProductId, @ItemID, @QuantityPurchased, @TransactionPrice,@CurrencyID,
@UserID, @SellerID, @ListingType, @TransactionStatus, @TransactionPlatform)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -1
END
--insert CHANNEL_EBAY_TRANSACTIONS_BUYER
INSERT INTO CHANNEL_EBAY_TRANSACTIONS_BUYER(Id, AddressID, AddressOwner, AddressRecordType, AddressStatus,
CityName, CompanyName, Country, CountryName, ExternalAddressID, InternationalName,
InternationalStateAndCity, InternationalStreet, Name, Phone, PostalCode,
StateOrProvince, Street, Street1, Street2)
VALUES (@Id, @AddressID, @AddressOwner, @AddressRecordType, @AddressStatus, @CityName, @CompanyName,
@Country, @CountryName, @ExternalAddressID, @InternationalName, @InternationalStateAndCity,
@InternationalStreet, @Name, @Phone, @PostalCode, @StateOrProvince, @Street, @Street1, @Street2)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -2
END
--insert CHANNEL_EBAY_TRANSACTIONS_DETAIL
INSERT INTO CHANNEL_EBAY_TRANSACTIONS_DETAIL(Id, BestOfferSale, BuyerMessage, QuantitySold, TransactionID,
FeedbackScore, StartTime, EndTime, BuyItNowPrice, StartPrice, CategoryID,RelistedItemID, Title)
VALUES (@Id, @BestOfferSale, @BuyerMessage, @QuantitySold,@TransactionID, @FeedbackScore, @StartTime,
@EndTime, @BuyItNowPrice, @StartPrice,@CategoryID, @RelistedItemID, @Title)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -3
END
--insert CHANNEL_EBAY_TRANSACTIONS_SHIPPING
INSERT INTO CHANNEL_EBAY_TRANSACTIONS_SHIPPING(Id, ShippingInsuranceCost, currencyID, ShippingService, ShippingServiceCost, ShippingServicePriority)
VALUES (@Id, @ShippingInsuranceCost, @currencyID, @ShippingService, @ShippingServiceCost, @ShippingServicePriority)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -4
END
--insert CHANNEL_EBAY_TRANSACTIONS_USER
INSERT INTO CHANNEL_EBAY_TRANSACTIONS_USER(Id, EIASToken, Email, FeedbackRatingStar, FeedbackScore, IDVerified,
NewUser, RegistrationDate, Site, Status, UniqueNegativeFeedbackCount,
UniquePositiveFeedbackCount, UserID, UserIDChanged, UserIDLastChanged, eBayGoodStanding)
VALUES (@Id, @EIASToken, @Email, @FeedbackRatingStar, @FeedbackScore, @IDVerified, @NewUser,
@RegistrationDate, @Site, @Status, @UniqueNegativeFeedbackCount, @UniquePositiveFeedbackCount,
@UserID, @UserIDChanged, @UserIDLastChanged, @eBayGoodStanding)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -5
END
--insert CHANNEL_EBAY_TRANSACTIONS_DETAIL
INSERT INTO Channel_Ebay_Transaction_PayRecord(Id,ItemID,TransactionID,CreatedDate,UserID,[Status])
Values(@Id,@ItemID,@TransactionID,@CreatedDate,@UserID,@DetailStatus)
IF @@Error <> 0
BEGIN
ROLLBACK
RETURN -6
END
--commit
COMMIT
return 1
END
调用后一直返回-1,这是什么问题啊?
c# 怎么调用,请给出调用代码。
2返回-1,这个结果是sqlserver管理器给出的返回值,还是c#程序给出的返回值
SqlConnection sqlconn = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand();
// 设置sql连接
cmd.Connection = sqlconn;
// 如果执行语句
cmd.CommandText = "Categoriestest1";
// 指定执行语句为存储过程
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter dp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
// 填充dataset
dp.Fill(ds);
// 以下是显示效果
GridView1.DataSource = ds;
GridView1.DataBind();2.没有输入输出的存储过程
SqlConnection sqlconn = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlconn;
cmd.CommandText = "Categoriestest2";
cmd.CommandType = CommandType.StoredProcedure;
sqlconn.Open();
// 执行并显示影响行数
Label1.Text = cmd.ExecuteNonQuery().ToString();
sqlconn.Close();3. 有返回值的存储过程SqlConnection sqlconn = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlconn;
cmd.CommandText = "Categoriestest3";
cmd.CommandType = CommandType.StoredProcedure;
// 创建参数
IDataParameter[] parameters = {
new SqlParameter("rval", SqlDbType.Int,4)
};
// 将参数类型设置为 返回值类型
parameters[0].Direction = ParameterDirection.ReturnValue;
// 添加参数
cmd.Parameters.Add(parameters[0]);
sqlconn.Open();
// 执行存储过程并返回影响的行数
Label1.Text = cmd.ExecuteNonQuery().ToString();
sqlconn.Close();
// 显示影响的行数和返回值
Label1.Text += "-" + parameters[0].Value.ToString() ;4. 有输入参数和输出参数的存储过程SqlConnection sqlconn = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlconn;
cmd.CommandText = "Categoriestest4";
cmd.CommandType = CommandType.StoredProcedure;
// 创建参数
IDataParameter[] parameters = {
new SqlParameter("@Id", SqlDbType.Int,4) ,
new SqlParameter("@CategoryName", SqlDbType.NVarChar,15) ,
};
// 设置参数类型
parameters[0].Direction = ParameterDirection.Output; // 设置为输出参数
parameters[1].Value = "testCategoryName";
// 添加参数
cmd.Parameters.Add(parameters[0]);
cmd.Parameters.Add(parameters[1]);
sqlconn.Open();
// 执行存储过程并返回影响的行数
Label1.Text = cmd.ExecuteNonQuery().ToString();
sqlconn.Close();
// 显示影响的行数和输出参数
Label1.Text += "-" + parameters[0].Value.ToString() ;
5. 同时具有返回值、输入参数、输出参数的存储过程
SqlConnection sqlconn = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlconn;
cmd.CommandText = "Categoriestest5";
cmd.CommandType = CommandType.StoredProcedure;
// 创建参数
IDataParameter[] parameters = {
new SqlParameter("@Id", SqlDbType.Int,4) ,
new SqlParameter("@CategoryName", SqlDbType.NVarChar,15) ,
new SqlParameter("rval", SqlDbType.Int,4)
};
// 设置参数类型
parameters[0].Direction = ParameterDirection.Output; // 设置为输出参数
parameters[1].Value = "testCategoryName"; // 给输入参数赋值
parameters[2].Direction = ParameterDirection.ReturnValue; // 设置为返回值
// 添加参数
cmd.Parameters.Add(parameters[0]);
cmd.Parameters.Add(parameters[1]);
cmd.Parameters.Add(parameters[2]);
sqlconn.Open();
// 执行存储过程并返回影响的行数
Label1.Text = cmd.ExecuteNonQuery().ToString();
sqlconn.Close();
// 显示影响的行数,输出参数和返回值
Label1.Text += "-" + parameters[0].Value.ToString() + "-" + parameters[2].Value.ToString();
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlconn;
cmd.CommandText = "Categoriestest6";
cmd.CommandType = CommandType.StoredProcedure;
// 创建参数
IDataParameter[] parameters = {
new SqlParameter("@Id", SqlDbType.Int,4) ,
new SqlParameter("@CategoryName", SqlDbType.NVarChar,15) ,
new SqlParameter("rval", SqlDbType.Int,4) // 返回值
};
// 设置参数类型
parameters[0].Direction = ParameterDirection.Output; // 设置为输出参数
parameters[1].Value = "testCategoryName"; // 给输入参数赋值
parameters[2].Direction = ParameterDirection.ReturnValue; // 设置为返回值
// 添加参数
cmd.Parameters.Add(parameters[0]);
cmd.Parameters.Add(parameters[1]);
cmd.Parameters.Add(parameters[2]);
SqlDataAdapter dp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
// 填充dataset
dp.Fill(ds);
// 显示结果集
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
Label1.Text = "";
// 显示输出参数和返回值
Label1.Text += parameters[0].Value.ToString() + "-" + parameters[2].Value.ToString();
7. 返回多个记录集的存储过程
SqlConnection sqlconn = new SqlConnection(conn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlconn;
cmd.CommandText = "Categoriestest7";
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter dp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
// 填充dataset
dp.Fill(ds);
// 显示结果集1
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
// 显示结果集2
GridView2.DataSource = ds.Tables[1];
GridView2.DataBind();
new SqlParameter("@ret",SqlDbType.Int,4),
//定义返回值参数
..........};这里面的参数太多了,就是你存储过程第一个AS
BEGIN
前面带@符号的for(int i=0;i<parm.Count;i++)
{
parm[i].Value = orderId;
..........
parm[**].Direction = ParameterDirection.ReturnValue;//是返回值类型
}
SqlConnection con=new SqlConnection(connstr);//链接字符串
SqlCommand cmd = new SqlCommand(procName, con); //也就是sp_transaction_order_Import
cmd.CommandType = CommandType.Text;
//执行类型:命令文本
// 依次把参数传入命令文本
if (prams != null)
{
foreach (SqlParameter parameter in prams)
cmd.Parameters.Add(parameter);
} con.Open();
cmd.ExecuteNonQuery();
//id就是你要取得id号
int id = Convert.ToInt32(pRet.Value);//取得返回值
conn.Close();