473,386 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

stored procedure have no results

my stored procedure:

create procedure ps_title @Title nchar(15)
AS
SELECT
,Title
FROM books
Where Title = @Title

this is my code. i'm passing variable to sp and getting no results.

protected void Button1_Click(object sender, EventArgs e)
{
SqlDataReader rdr = null;
SqlConnection con = null;
SqlCommand cmd = null;

try
{

string conn =
@"server=local;uid=;pwd=;trusted_connection=true;d atabase=library";
con = new SqlConnection(conn);
con.Open();

cmd = new SqlCommand("ps_title", con);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@Book",
System.Data.SqlDbType.NVarChar).Value = drpdbooks.Text;
// Execute the query
rdr = cmd.ExecuteReader();
}
}

Jan 12 '07 #1
6 1496
<ch********@yahoo.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
SELECT
,Title
FROM books
Where Title = @Title
Does that not generate an error...? It certainly should do, because of the
apostrophe...
Jan 12 '07 #2
I re-wrote the statement and made an error. If anyone has any
suggestions.
Thanx


Mark Rae wrote:
<ch********@yahoo.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
SELECT
,Title
FROM books
Where Title = @Title

Does that not generate an error...? It certainly should do, because of the
apostrophe...
Jan 12 '07 #3
<ch********@yahoo.comwrote in message
news:11**********************@11g2000cwr.googlegro ups.com...
I re-wrote the statement and made an error.
Sigh...

What was the error...?
Jan 12 '07 #4
>From the listed stored procedure and C#.Net script I'm receiving no
error messages, but I'm also receiving blank records (no records at
all).

Mark Rae wrote:
<ch********@yahoo.comwrote in message
news:11**********************@11g2000cwr.googlegro ups.com...
I re-wrote the statement and made an error.

Sigh...

What was the error...?
Jan 12 '07 #5
I think what Mark meant was "Re-post your (corrected) code."

Robin S.
--------------------------
<ch********@yahoo.comwrote in message
news:11**********************@51g2000cwl.googlegro ups.com...
From the listed stored procedure and C#.Net script I'm receiving no
error messages, but I'm also receiving blank records (no records at
all).

Mark Rae wrote:
><ch********@yahoo.comwrote in message
news:11**********************@11g2000cwr.googlegr oups.com...
I re-wrote the statement and made an error.

Sigh...

What was the error...?

Jan 12 '07 #6
sorry i am. im new with c.net coming from cold fusion. so locating
stacktrace and hasrows property are really new to me. when working in
the query analyzer and using
ps_title 'Computers', returns records.

thanks for everyone
create procedure ps_title @Title nchar(15)
AS
SELECT Title FROM books
Where Title = @Title
this is my code. i'm passing variable to sp and getting no results.
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataReader rdr = null;
SqlConnection con = null;
SqlCommand cmd = null;
try
{
string conn =
@"server=local;uid=;pwd=;trusted_connection=true;d atabase=library";
con = new SqlConnection(conn);
con.Open();
cmd = new SqlCommand("ps_title", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Book",
System.Data.SqlDbType.NVarChar).Value = drpdbooks.Text;
// Execute the query
rdr = cmd.ExecuteReader();
}
}
lbFound.Items.Clear();
while (rdr.Read())
{
titles.Items.Add(rdr["Title"].ToString();
}
}
catch (SqlException ex)
{
}
finally
{
// Close data reader object and database connection
if (rdr != null)
rdr.Close();

if (con.State == ConnectionState.Open)
con.Close();
}
}


Peter Bromberg [ C# MVP ] wrote:
You have a try block, but no catch block. So even if your code is throwing an
exception you would not know about it. Put a catch(SqlException ex) bloc
after your try block and output any exception Message and StackTrace to the
debug window.

Finally, maybe your stored proc and parameter just arent returning any rows.
Have you looked at the HasRows property of your DataReader?

You have to code defensively, or you are going to be asking a lot of
questions on newsgroups and waiting around for answers.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"ch********@yahoo.com" wrote:
my stored procedure:

create procedure ps_title @Title nchar(15)
AS
SELECT
,Title
FROM books
Where Title = @Title

this is my code. i'm passing variable to sp and getting no results.

protected void Button1_Click(object sender, EventArgs e)
{
SqlDataReader rdr = null;
SqlConnection con = null;
SqlCommand cmd = null;

try
{

string conn =
@"server=local;uid=;pwd=;trusted_connection=true;d atabase=library";
con = new SqlConnection(conn);
con.Open();

cmd = new SqlCommand("ps_title", con);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add("@Book",
System.Data.SqlDbType.NVarChar).Value = drpdbooks.Text;
// Execute the query
rdr = cmd.ExecuteReader();
}
}
Jan 12 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jarrod Morrison | last post by:
Hi All I have a stored procedure with a temporary table that with two columns in it. The first column contains 3 digit numbers and the second column some descriptive data. I was wondering what...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
0
by: James Hokes | last post by:
Hi All, We're using the 1.1. Framework against SQL Server 2000, and are having a strange issue where we don't get errors back from the stored procedure, i.e. the exception never gets thrown. ...
4
by: John | last post by:
Hi everyone, I have a stored procedure which I use to query a table. The first part of the stored procedure uses a cursor to update a temp table whilst the second part of the query actually...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
2
by: Carl San | last post by:
I am using ADO.Net in VB.net application. .Net Framework 1.1. In a stored procedure I have multiple output parameters and multiple result sets. How to code for this in ADO.Net? I have used...
4
by: jaYPee | last post by:
I have downloaded some source code but I want this to convert the results into datagrid. dr = cmd.ExecuteReader() '**************************************** ' SHOW THE RESULTS...
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
7
by: eholz1 | last post by:
Hello PHP group, Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0 running on Linux (Redhat Fedora Core 6). All that works fine. I would like to be able to "call" a stored...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.