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