我正在尝试修复这个旧的asp.net页面并且我不断获得'过程或函数Top100指定了太多参数。这个错误只发生在你点击网站的“前10名”按钮我不知道该怎么做,因为我对c#很新。我还不知道我的方式。
public SqlDataReader ExecuteQuery(string strSql)
{
MsSqlConnection = OpenConnection();
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.Text;
command.CommandText = strSql;
command.Connection = MsSqlConnection;
MsSqlConnection.Open();
SqlDataReader reader = command.ExecuteReader();
return reader;
}
Top100代码:
public DataTable Top100(int nation, int class_)
{
string strSql = "exec DragonRajaDB.dbo.Top100 " + Convert.ToInt32(nation) + "," + Convert.ToInt32(class_);
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Rank", typeof(int)));
dt.Columns.Add(new DataColumn("Name", typeof(String)));
dt.Columns.Add(new DataColumn("Lev", typeof(int)));
dt.Columns.Add(new DataColumn("Class", typeof(String)));
dt.Columns.Add(new DataColumn("Nation", typeof(String)));
dt.Columns.Add(new DataColumn("Guild", typeof(String)));
dt.Columns.Add(new DataColumn("GuildLogoURL", typeof(String)));
using (SqlDataReader reader = ExecuteQuery(strSql))
{
int i = 1;
while (reader.Read())
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = reader.GetSqlString(0).Value;
dr[2] = reader.GetSqlInt32(1).Value;
int playerClass = reader.GetSqlInt32(2).Value;
switch (playerClass)
{
case 0:
dr[3] = "Warrior";
break;
case 1:
dr[3] = "Thief";
break;
case 2:
dr[3] = "Archer";
break;
case 3:
dr[3] = "Wizard";
break;
case 4:
dr[3] = "Priest";
break;
default:
dr[3] = "Unknown";
break;
}
dr[4] = reader.GetSqlString(3).Value;
if (reader.GetSqlString(4).IsNull)
{
dr[5] = "";
dr[6] = "";
}
else
{
dr[5] = reader.GetSqlString(4).Value;
int guildCode = reader.GetSqlInt32(5).Value;
dr[6] = "guildlogos/guild" + guildCode.ToString() + ".gif";
}
dt.Rows.Add(dr);
i++;
}
}
return dt;
}
这是存储过程:
USE [Dragonrajadb]
GO
/****** Object: StoredProcedure [dbo].[Top100] Script Date: 10/21/2014 11:02:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[Top100]
@nation int = 0
AS
DECLARE @SQLString NVARCHAR(500)
SET @SQLString = N'SELECT top 100 name, lev, exp, nation from chr_info where name not in (''GM01'') '
if @nation <> 0
begin
if @nation = 6
begin
set @SQLString = @SQLString + ' and nation in (6,22,38,14,30,38)'
end
else if @nation = 3
begin
set @SQLString = @SQLString + ' and nation not in (4,20,12,28,36,6,22,38,14,30,38)'
end
else if @nation = 4
begin
set @SQLString = @SQLString + ' and nation in (4,20,12,28,36)'
end
end
set @SQLString = @SQLString + ' order by lev desc, exp desc'
EXECUTE sp_executesql @SQLString
答案 0 :(得分:1)
程序Top100
只有一个参数,即:nation
:
ALTER Procedure [dbo].[Top100]
@nation int = 0 -- just one parameter
AS
...
您正在尝试指定第二个参数:class
:
string strSql = "exec DragonRajaDB.dbo.Top100 " + nation + "," + class_;
因此,删除class
参数:
string strSql = "exec DragonRajaDB.dbo.Top100 " + nation