Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the problem in the following code?i want to give the scalar function the parameter iddoc for @iddoctor and get the result in the txt box



SqlConnection conn = new SqlConnection
            ("Data Source=(LocalDB)\\v11.0;Integrated Security=True");

        conn.Open();
        SqlCommand cmd = new SqlCommand("SELECT * FROM [dbo].[name_of_the_doctor](@iddoctor);", conn);
        SqlParameter code1 = new SqlParameter("@iddoctor", SqlDbType.Int);
        cmd.Parameters.Add(code1);
        cmd.Parameters["@iddoctor"].Value = iddoc;
        textBox1.Text = cmd.ExecuteScalar().ToString();
Posted
Comments
OriginalGriff 24-May-15 6:45am    
And?
What happens when you try?
Member 10491587 24-May-15 6:57am    
i get the error that the object [dbo].[name_of_the_doctor] doesn't exist
Member 10491587 24-May-15 6:59am    
information: Invalid object name 'dbo.name_of_the_doctor'.

1 solution

"i get the error that the object [dbo].[name_of_the_doctor] doesn't exist"

Error messages are supposed to give you a small clue as to what you are doing wrong: in this case a very quick read of the error message should tell you what you need to do.

Check your database: look under "Programmability"..."Functions"..."Scalar-values Functions" and check that a function called "name_of_the_doctor" exists.

If it doesn't, then you need to write it...
If it does, try this:
C#
SqlCommand cmd = new SqlCommand("SELECT dbo.name_of_the_doctor(@iddoctor);", conn);


[edit]Markdown strikes again![/edit]
 
Share this answer
 
v2
Comments
Member 10491587 24-May-15 10:31am    
it does and now :
having a new error:'name_of_the_doctor' is not a recognized built-in function name.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900