开发者

asp.net stored procedure problem

开发者 https://www.devze.com 2022-12-27 05:14 出处:网络
Why this code don\'t work,when i want run this code vwd 2008 express show me this error message:Invalid object name \'answers\'.

Why this code don't work,when i want run this code vwd 2008 express show me this error message:Invalid object name 'answers'.

this is my ascx.cs code:

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 Sq开发者_StackOverflowlParameter("@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();

    }

}

    }
}

and this is my stored procedure :

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


Looks like you don't have an answers table in your dbo schema of the estudent_pioo database on the xxxxx\PADME server.

And the stored procedure you posted is would not even run. Perhaps you meant:

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


The problem seems to exist in your procedure... Are you sure that Answer table exist and belongs to dbo schema?


Make sure you've specified the correct DB to connect to in the connection string


Is 'answers' a table or view in the same DB as your stored procedure? Try running the stored procedure directly from SQL.

Looks like you are also going to have problems with the parameter. Should be @count?

0

精彩评论

暂无评论...
验证码 换一张
取 消