asp.net存储过程问题
为什么这段代码不起作用,当我想运行这段代码时,vwd 2008 express向我显示以下错误消息:无效的对象名称“answers” 这是我的ascx.cs代码:asp.net存储过程问题,asp.net,Asp.net,为什么这段代码不起作用,当我想运行这段代码时,vwd 2008 express向我显示以下错误消息:无效的对象名称“answers” 这是我的ascx.cs代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Web.UI; using System.Web.UI.WebControls; using Syst
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data.SqlClient;
using System.Configuration;
public partial class odgl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
string connectionString =
@"SANATIZEDSTRING!!!!";
using (SqlConnection cn = new SqlConnection(connectionString))
{
using (SqlCommand dohvati = new SqlCommand("dbo.get_answers",cn)) {
dohvati.CommandType = CommandType.StoredProcedure;
SqlParameter izracun = new SqlParameter("@count", SqlDbType.Int);
izracun.Direction = ParameterDirection.Output;
dohvati.Parameters.Add(izracun);
cn.Open();
dohvati.ExecuteNonQuery();
int count = Int32.Parse(dohvati.Parameters["@count"].Value.ToString());
Response.Write(count.ToString());
cn.Close();
}
}
}
}
这是我的存储过程
:
这个问题似乎存在于你的程序中。。。您确定应答表存在并且属于dbo模式吗?您的过程中似乎存在问题。。。您确定应答表存在并且属于dbo架构吗?应答表是与存储过程位于同一数据库中的表还是视图? 尝试直接从SQL运行存储过程
看起来您的参数也会有问题。应该是@count?与存储过程在同一数据库中的“answers”是表还是视图? 尝试直接从SQL运行存储过程
看起来您的参数也会有问题。应该是@count?看起来您在
xxxxx\PADME
服务器上的estudent\u pioo
数据库的dbo
架构中没有answers
表
您发布的存储过程甚至不会运行。也许你的意思是:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[get_answers]
@count int output
as
select @count= (SELECT COUNT(*) FROM answers)
go
在
xxxxx\PADME
服务器上的estudent\u pioo
数据库的dbo
架构中,似乎没有answers
表
您发布的存储过程甚至不会运行。也许你的意思是:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[get_answers]
@count int output
as
select @count= (SELECT COUNT(*) FROM answers)
go
确保在连接字符串中指定了要连接到的正确DB确保在连接字符串中指定了要连接到的正确DB以供将来参考,切勿将SQL Server连接字符串包含在您放在网站上供全世界查看的代码中。为了将来参考,永远不要将SQL Server连接字符串包含在您放在网站上供全世界查看的代码中。