0

This is my SP code

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE SP_Get_Age
    @name varchar(20)   
AS
BEGIN
    SET NOCOUNT ON;
    SELECT Age  FROM PersonDetails WHERE Name1 = @name;
END
GO

This is my C# code

 private void callSP(string name1)//name1 comes properly in button click event
        {
            using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection())
            {
              String connectionString = "Server=PRASAD-PC\\SQLEXPRESS;Database=MyDB;   Trusted_Connection=True;";
                con.ConnectionString = connectionString;

                con.Open();
                SqlCommand cmd = new SqlCommand("SP_Get_Age", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@name", name1));

                SqlDataReader rdr = cmd.ExecuteReader();//This line shows the error "Invaid object name PersonDetails"

            while (rdr.Read())
            {
                textBox1.Text = Convert.ToString( rdr["Age"]);
            }
            con.Close();

        }
    }

I re-checked my spellings. But no any error on it. Please tell me why it is showing "Invaid object name PersonDetails"????

Edited by Reverend Jim: wrong forum

4
Contributors
6
Replies
26
Views
4 Years
Discussion Span
Last Post by Reverend Jim
0

I didn't get you JorgeM. (I'm bit new to this technology and dont know much about SP)

0

What I mean is that why would you be running a stored procedure that seems to be creating a new stored procedure. Are you sure that's your SP code? Maybe I'm confused..

Edited by JorgeM

0

Could be working for a company that doesn't know the value of training.

If you think education is expensive consider the cost of ignorance - Unknown

Edited by Reverend Jim

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.