C#写SQL语句出错,提示 必须声明标量变量 "@TweetID"!
publicintAdd(stringTweetComment,stringUser_Phone,stringTW_PhoneModel){StringBuilderst...
public int Add(string TweetComment, string User_Phone, string TW_PhoneModel)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("INSERT INTO TW_TweetComment (TweetComment,TweetID,TweetCommentPID,TC_PromotersDeID,TC_PromotersDe,TC_PromotersID,TC_PromotersName,TC_StartTime) ");
strSql.Append(" SELECT @TweetID ,@TweetComment,1,Organization_ID ,Organization_Name ,User_ID ,USER_NAME ,GETDATE() ,0 FROM View_Base_UserInfo WHERE User_Phone=@User_Phone ");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@TweetComment", SqlDbType.NVarChar,500),
new SqlParameter("@User_Phone", SqlDbType.VarChar,11),
new SqlParameter("@TW_PhoneModel", SqlDbType.VarChar,20)};
parameters[0].Value = TweetComment;
parameters[1].Value = User_Phone;
parameters[2].Value = TW_PhoneModel;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
//这句出现错误,提示 必须声明标量变量 "@TweetID" 展开
{
StringBuilder strSql = new StringBuilder();
strSql.Append("INSERT INTO TW_TweetComment (TweetComment,TweetID,TweetCommentPID,TC_PromotersDeID,TC_PromotersDe,TC_PromotersID,TC_PromotersName,TC_StartTime) ");
strSql.Append(" SELECT @TweetID ,@TweetComment,1,Organization_ID ,Organization_Name ,User_ID ,USER_NAME ,GETDATE() ,0 FROM View_Base_UserInfo WHERE User_Phone=@User_Phone ");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@TweetComment", SqlDbType.NVarChar,500),
new SqlParameter("@User_Phone", SqlDbType.VarChar,11),
new SqlParameter("@TW_PhoneModel", SqlDbType.VarChar,20)};
parameters[0].Value = TweetComment;
parameters[1].Value = User_Phone;
parameters[2].Value = TW_PhoneModel;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
//这句出现错误,提示 必须声明标量变量 "@TweetID" 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询