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"????

You are executing a procedure that is creating a procedure?

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

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

Member Avatar for iamthwee

I hope the OP isn't employed and working for a company. That would be worrying.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.