asp.net stored procedure problem
Posted
by kenom
on Stack Overflow
See other posts from Stack Overflow
or by kenom
Published on 2010-04-19T19:54:58Z
Indexed on
2010/04/19
20:03 UTC
Read the original article
Hit count: 218
ASP.NET
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 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();
}
}
}
}
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
© Stack Overflow or respective owner