为什么这段代码不起作用,当我想运行此代码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 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();
}
}
}
}
这是我的存储过程 :
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[get_answers]
@ukupno int output
as
select @count= (SELECT COUNT(*) FROM answers)
go
答案 0 :(得分:3)
您answers
服务器上dbo
数据库的estudent_pioo
架构中似乎没有xxxxx\PADME
表。
您发布的存储过程甚至不会运行。也许你的意思是:
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
答案 1 :(得分:1)
问题似乎存在于您的程序中......您确定答案表存在且属于dbo架构吗?
答案 2 :(得分:1)
确保您已在连接字符串中指定了要连接的正确数据库
答案 3 :(得分:0)
与应用存储过程在同一个数据库中“回答”表或视图吗? 尝试直接从SQL运行存储过程。
看起来你也会遇到参数问题。应该是@count?