Asp.net 使用MSSQLSProvider.ExecProcedure的存储过程和方法中的语法是否正确?

Asp.net 使用MSSQLSProvider.ExecProcedure的存储过程和方法中的语法是否正确?,asp.net,sql-server,Asp.net,Sql Server,我对ASP.net和存储过程有问题 我在SQL Server中的过程: ALTER PROCEDURE [dbo].[top1000] @Published datetime output, @Title nvarchar(100) output, @Url nvarchar(1000) output, @Count INT output AS SET @Published = (SELECT T

我对ASP.net和存储过程有问题

我在SQL Server中的过程:

ALTER PROCEDURE [dbo].[top1000]
            @Published datetime output,
            @Title nvarchar(100) output,
            @Url nvarchar(1000) output,
            @Count INT output

AS 
SET @Published = (SELECT TOP 1000  dbo.vst_download_files.dfl_date_public FROM dbo.vst_download_files
    ORDER BY dbo.vst_download_files.dfl_download_count DESC )
SET @Title = (SELECT TOP 1000  dbo.vst_download_files.dfl_name FROM dbo.vst_download_files
    ORDER BY dbo.vst_download_files.dfl_download_count DESC) 
SET @Url = (SELECT TOP 1000  dbo.vst_download_files.dfl_source_url FROM dbo.vst_download_files
    ORDER BY dbo.vst_download_files.dfl_download_count DESC) 
SET @Count = (SELECT TOP 1000  dbo.vst_download_files.dfl_download_count FROM dbo.vst_download_files
    ORDER BY dbo.vst_download_files.dfl_download_count DESC) 
以及我在网站项目中的程序

public static void Top1000()
{
        List<DownloadFile> List = new List<DownloadFile>();
        SqlDataReader dbReader;

        SqlParameter published = new SqlParameter("@Published", SqlDbType.DateTime2);
        published.Direction = ParameterDirection.Output;
        SqlParameter title = new SqlParameter("@Title", SqlDbType.NVarChar);
        title.Direction = ParameterDirection.Output;
        SqlParameter url = new SqlParameter("@Url", SqlDbType.NVarChar);
        url.Direction = ParameterDirection.Output;
        SqlParameter count = new SqlParameter("@Count", SqlDbType.Int);
        count.Direction = ParameterDirection.Output;
        SqlParameter[] parm = {published, title, count};

        dbReader = MsSqlProvider.ExecProcedure("top1000", parm);

        try
        {
            while (dbReader.Read())
            {
                DownloadFile df = new DownloadFile();
                //df.AddDate = dbReader["dfl_date_public"];
                df.Name = dbReader["dlf_name"].ToString();
                df.SourceUrl = dbReader["dlf_source_url"].ToString();
                df.DownloadCount = Convert.ToInt32(dbReader["dlf_download_count"]);
                List.Add(df);
            }

            XmlDocument top1000Xml = new XmlDocument();
            XmlNode XMLNode = top1000Xml.CreateElement("products");

            foreach (DownloadFile df in List)
            {
                XmlNode productNode = top1000Xml.CreateElement("product");

                XmlNode publishedNode = top1000Xml.CreateElement("published");
                publishedNode.InnerText = "data dodania";
                XMLNode.AppendChild(publishedNode);

                XmlNode titleNode = top1000Xml.CreateElement("title");
                titleNode.InnerText = df.Name;
                XMLNode.AppendChild(titleNode);
            }

            top1000Xml.AppendChild(XMLNode);
            top1000Xml.Save("\\pages\\test.xml");
        }
        catch
        {
        }
        finally
        {
            dbReader.Close();
        }
    }
publicstaticvoidtop1000()
{
列表=新列表();
SqlDataReader-dbReader;
SqlParameter published=新的SqlParameter(“@published”,SqlDbType.DateTime2);
published.Direction=参数Direction.Output;
SqlParameter title=新的SqlParameter(“@title”,SqlDbType.NVarChar);
title.Direction=参数Direction.Output;
SqlParameter url=新的SqlParameter(“@url”,SqlDbType.NVarChar);
url.Direction=ParameterDirection.Output;
SqlParameter count=新的SqlParameter(“@count”,SqlDbType.Int);
count.Direction=参数Direction.Output;
SqlParameter[]parm={已发布,标题,计数};
dbReader=MsSqlProvider.ExecProcedure(“top1000”,parm);
尝试
{
while(dbReader.Read())
{
DownloadFile df=新的DownloadFile();
//df.AddDate=dbReader[“dfl_date_public”];
df.Name=dbReader[“dlf_Name”].ToString();
df.SourceUrl=dbReader[“dlf_source_url”].ToString();
df.DownloadCount=Convert.ToInt32(dbReader[“dlf_DownloadCount”]);
列表。添加(df);
}
XmlDocument top1000Xml=新的XmlDocument();
XmlNode XmlNode=top1000Xml.CreateElement(“产品”);
foreach(下载列表中的文件df)
{
XmlNode productNode=top1000Xml.CreateElement(“产品”);
XmlNode publishedNode=top1000Xml.CreateElement(“已发布”);
publishedNode.InnerText=“data dodania”;
AppendChild(publishedNode);
XmlNode titleNode=top1000Xml.CreateElement(“标题”);
titleNode.InnerText=df.Name;
AppendChild(titleNode);
}
top1000Xml.AppendChild(XMLNode);
top1000Xml.Save(“\\pages\\test.xml”);
}
抓住
{
}
最后
{
dbReader.Close();
}
}
如果我使用
MsSqlProvider.ExecProcedure(“top1000”,parm)我得到了

字符串[1]:属性大小的大小0无效


我应该在哪里寻找解决方案?过程或方法?

您需要为url和标题指定长度属性

SqlParameter title = new SqlParameter("@Title", SqlDbType.NVarChar); 
title.Size=1000

SqlParameter url = new SqlParameter("@Url", SqlDbType.NVarChar); 
url.Size=1000
您可以像下面这样更改查询,而不是使用输出参数

ALTER PRocedure [dbo].[top1000]
As
Begin 
Select top 1000 dfl_date_public ,dfl_name,dfl_source_url,
dfl_download_count from dbo.vst_download_files
order  by dbo.vst_download_files.dfl_download_count DESC 
然后使用执行读取器

SqlCommand command =
        new SqlCommand("top1000", connection);
command.CommandType=CommandType.StoredProcedure
 SqlDataReader reader = command.ExecuteReader();
 // Iterate through reader as u did and add it to the collection 
使用xelement构建XML的框架

   foreach (DownloadFile df in List) 
        {
   XElement products=
new XElement("Products",
    new XElement("product",
        new XElement("published", "data dodania"),
        new XElement("title", df.Name) 
                 );
         }

在Sql Server Management Studio上执行该过程,查看返回的内容是否是您要查找的内容。另外,在这些情况下,使用VisualStudio的调试器有很大帮助?我认为应该是
SqlParameter[]parm={published,title,url,count}
@Steve:我这样做了,
命令成功完成。
@Pabloker:我的输入错误,当然在我的代码中是url:)您的sp中的SQL似乎也有问题,@Count希望您返回int,但您尝试返回其中的1000行?我不是职业选手,但这看起来不像right@Steve我想我知道你想说什么,所以我应该用ArrayTanks,现在我更接近了,现在它告诉我Steve说。我只需要选择一个元素。你的评论xD让我很开心,谢谢你帮我救了我的命。