|M| 第三贴:我的一个存储过程,如何返回值啊要怎么写 我写的出错 谢谢 超急啊
存储过程
CREATE PROCEDURE [insert_ConcertSite_1]
(
@SiteID int output,
@CityID_1 [int],
@SupplierID_2 [int],
@Address_3 [nvarchar](500),
@SiteName_4 [nvarchar](50),
@MapRoad_5 [nvarchar](500),
@SitePic_6 [nvarchar](500),
@Intro_7 [nvarchar](4000),
@Remark_8 [text])
AS INSERT INTO [HotelBook].[dbo].[ConcertSite]
( [CityID],
[SupplierID],
[Address],
[SiteName],
[MapRoad],
[SitePic],
[Intro],
[Remark])
VALUES
( @CityID_1,
@SupplierID_2,
@Address_3,
@SiteName_4,
@MapRoad_5,
@SitePic_6,
@Intro_7,
@Remark_8)
SET @SiteID = (SELECT scope_identity() )
GO
ASP.NET:
SqlConnection con = ConcertDB.createcon();
SqlCommand com = new SqlCommand( "insert_ConcertSite_1 ", con);
com.CommandType = CommandType.StoredProcedure;
SqlParameter spt = new SqlParameter();
spt = new SqlParameter( "@SiteID ", SqlDbType.Int, 4);
spt.Direction = ParameterDirection.Output;
com.Parameters.Add(spt);
spt = new SqlParameter( "@CityID ", SqlDbType.Int, 4);
spt.Value = ddl_CityName.SelectedValue;
com.Parameters.Add(spt);
spt = new SqlParameter( "@SupplierID ", SqlDbType.Int, 4);
spt.Value = txt_SupplierID.Value;
com.Parameters.Add(spt);
spt = new SqlParameter( "@Address ", SqlDbType.NVarChar, 500);
spt.Value = txt_Address.Text;
com.Parameters.Add(spt);
spt = new SqlParameter( "@SiteName ", SqlDbType.NVarChar, 50);
spt.Value = txt_SiteName.Text;
com.Parameters.Add(spt);
spt = new SqlParameter( "@MapRoad ", SqlDbType.NVarChar, 500);
spt.Value = fud_MapRoad.FileName;
com.Parameters.Add(spt);
spt = new SqlParameter( "@SitePic ", SqlDbType.NVarChar, 500);
spt.Value = fud_SitePic.FileName;
com.Parameters.Add(spt);
spt = new SqlParameter( "@Intro ", SqlDbType.NVarChar, 4000);
spt.Value = txt_Intro.Text;
com.Parameters.Add(spt);
spt = new SqlParameter( "@Remark ", SqlDbType.Text, 16);
spt.Value = txt_Remark.Text;
com.Connection.Open();
int i = Convert.ToInt32(com.ExecuteNonQuery());
int outID = (int)com.Parameters[ "@SiteID "].Value;
com.Connection.Close();
以上出错:
这条int i = Convert.ToInt32(com.ExecuteNonQuery());
提示:将参数值从 String 转换到 Int32 失败。
我想应该是这里出错:
spt = new SqlParameter( "@SiteID ", SqlDbType.Int, 4);
spt.Direction = ParameterDirection.Output;
com.Parameters.Add(spt);
要怎么改啊..谢谢
很急啊
------解决方案--------------------