none
为什么我的存储过程明明是检验数据,怎么变成添加数据了啊? RRS feed

  • 问题

  • 我的存储过程是:
    create proc Validate_TableName
    @TableName varchar(50),
    @TableWhere varchar(200),
    @RecordCount int OUTPUT   --总记录数(存储过程输出参数)
    as
    declare @TmpSelect Nvarchar(600)
    declare @Count int
    set @TmpSelect='select @RecordCount = count(*) from '+@TableName+' where '+@TableWhere
    execute sp_executesql @TmpSelect,N'@RecordCount int output',@RecordCount output
    if (0 > @RecordCount)
        return (-1)
    else if (@RecordCount = 0)
     return (0)
    else
     return (1)
    go

    为什么我的程序每次检验一次就会数据就会输入一次数据啊?
    public static int Volidata(string TableName, string SelectWhere)
            {
                int iRet;
                using (SqlConnection conn = new SqlConnection(DBSQL))
                {
                    SqlCommand scmd = new SqlCommand("Validate_TableName", conn);
                    scmd.CommandType = CommandType.StoredProcedure;

                    scmd.Parameters.AddWithValue("@TableName", TableName);
                    scmd.Parameters.AddWithValue("@TableWhere", SelectWhere);

                    scmd.Parameters.Add(new SqlParameter("@RecordCount", SqlDbType.Int, 4));
                    scmd.Parameters["@RecordCount"].Direction = ParameterDirection.Output;//

                    conn.Open();
                    //在返回值上有问题
                    scmd.ExecuteNonQuery();
                    iRet = (int)scmd.Parameters["@RecordCount"].Value;
                    return iRet;
                }

            }
    请帮我看看,有哪里出错了啊?

    2009年10月23日 2:20

答案

全部回复