stored procedure have no results

C

chessitguy

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;database=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();
}
}
 
C

chessitguy

I re-wrote the statement and made an error. If anyone has any
suggestions.
Thanx
 
C

chessitguy

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).
 
R

RobinS

I think what Mark meant was "Re-post your (corrected) code."

Robin S.
--------------------------
 
C

chessitguy

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;database=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();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Parameters passed to Stored Procedure not working 2
Output parameter when using storedProcedure 14
using stored procedure 3
about performance 2
blob 9
data in grid 1
Generic Database handling class 13
tables search 2

Top