How to pass parameter correctly into C# when using sql function

  • I am not familiar using function and the parameter is already inside the function.When I call the data inside my C#, it is throwing error and unable to run. I was just using basic SQL query constantly and got it running.

    How could I solve it in this case?

    Greatly appreciate any insight.

    string sqlDetails = "SELECT ....... FROM dbo.fn_GetDetails(12345)";

    SqlConnection connection = new SqlConnection("Data Source=localhost; " + "Initial Catalog=DB; " + "Integrated Security=SSPI");

    SqlCommand command = new SqlCommand(sqlDetails, connection);

    command.Parameters.Add(new SqlParameter("ID", 12345));

    SqlDataAdapter TableAdapter = new SqlDataAdapter(command);

    TableAdapter.Fill(DsOrder, "DetailsInfo");

  • Newbi (11/9/2016)


    I am not familiar using function and the parameter is already inside the function.When I call the data inside my C#, it is throwing error and unable to run. I was just using basic SQL query constantly and got it running.

    How could I solve it in this case?

    Greatly appreciate any insight.

    string sqlDetails = "SELECT ....... FROM dbo.fn_GetDetails(12345)";

    SqlConnection connection = new SqlConnection("Data Source=localhost; " + "Initial Catalog=DB; " + "Integrated Security=SSPI");

    SqlCommand command = new SqlCommand(sqlDetails, connection);

    command.Parameters.Add(new SqlParameter("ID", 12345));

    SqlDataAdapter TableAdapter = new SqlDataAdapter(command);

    TableAdapter.Fill(DsOrder, "DetailsInfo");

    Looking at the snippet you posted, I suggest you read up on the SqlCommand Class

    😎

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply