C#写的SQL语句提示说“必须申明标量变量”!
publicintAdd(stringTW_TwitterContent,stringUser_Phone,stringTW_PhoneModel){StringBuil...
public int Add(string TW_TwitterContent, string User_Phone, string TW_PhoneModel)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("INSERT INTO TW_Tweet (TW_TwitterContent,TW_PhoneModel,TW_TwitterType,TW_PromotersDeID,TW_PromotersDe,TW_PromotersID,TW_PromotersName,TW_StartTime,TW_TotalNumber) ");
strSql.Append(" SELECT @TW_TwitterContent ,@TW_PhoneModel,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("@TW_TwitterContent", SqlDbType.NVarChar,500),
new SqlParameter("@User_Phone", SqlDbType.VarChar,11),
new SqlParameter("@TW_PhoneModel", SqlDbType.VarChar,20)};
parameters[0].Value = TW_TwitterContent;
parameters[1].Value = User_Phone;
parameters[2].Value = TW_PhoneModel;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); //提示“必须申明标量变量” 展开
{
StringBuilder strSql = new StringBuilder();
strSql.Append("INSERT INTO TW_Tweet (TW_TwitterContent,TW_PhoneModel,TW_TwitterType,TW_PromotersDeID,TW_PromotersDe,TW_PromotersID,TW_PromotersName,TW_StartTime,TW_TotalNumber) ");
strSql.Append(" SELECT @TW_TwitterContent ,@TW_PhoneModel,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("@TW_TwitterContent", SqlDbType.NVarChar,500),
new SqlParameter("@User_Phone", SqlDbType.VarChar,11),
new SqlParameter("@TW_PhoneModel", SqlDbType.VarChar,20)};
parameters[0].Value = TW_TwitterContent;
parameters[1].Value = User_Phone;
parameters[2].Value = TW_PhoneModel;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); //提示“必须申明标量变量” 展开
1个回答
展开全部
select 语句中的字段列表中不能使用参数;参数只能出现在where子句中,修改成
……
strSql.Append(" SELECT TW_TwitterContent ,TW_PhoneModel,1,Organization_ID ,Organization_Name ,User_ID ,USER_NAME ,GETDATE() ,0 FROM View_Base_UserInfo WHERE User_Phone=@User_Phone ");
……
//只有一个参数了
SqlParameter[] parameters = {new SqlParameter("@User_Phone", SqlDbType.VarChar,11)};
parameters[0].Value = User_Phone;
……
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询