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