Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1042971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:35:31+00:00 2026-05-16T15:35:31+00:00

I have the following c# code to call stored procedure testproc , but when

  • 0

I have the following c# code to call stored procedure testproc, but when I run this application it says that it could not find stored procedure testproc.

This is my c# code behind to call the stored procedure:

SqlConnection con = new SqlConnection();
con.ConnectionString = "data source='example.com';user id='sa';password='password';persist security info=False;initial catalog=Test;Connect Timeout=100; Min Pool Size=100; Max Pool Size=500";
con.Open();

DataSet ds = new DataSet();
SqlCommand com = new SqlCommand("testproc",con );
SqlDataAdapter sqlda = new SqlDataAdapter(com);
//sqlda.SelectCommand.CommandText = "SELECT Id,Name1,ZipCode,StreetName,StreetNumber,State1,Lat,Lng,Keyword, ( 6371 * ACOS( COS( (12.925432/57.2958) ) * COS(  (Lat/57.2958)  ) * COS( ( Lng/57.2958 ) - (77.5940171/57.2958) ) + SIN( 12.925432/57.2958 ) * SIN(  Lat/57.2958  ) ) ) AS distance FROM Business_Details where( (StreetName like '%jayanagar%')and (Keyword like '%plumbing%' ))ORDER BY distance;";
//sqlda.CommandText = "select * from business where(( distance<'" + radius + "' )and (StreetName like '%" + streetname + "%')and (Keyword like '%" + keyword1 + "%' )) order by distance";
//com.CommandText = "testproc ";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add(new SqlParameter("@lat1",SqlDbType.Float,50,lat1));
com.Parameters.Add(new SqlParameter("@lng1",SqlDbType.Float,50,lng1));
com.Parameters.Add(new SqlParameter("@radius1",SqlDbType.Int,10,radius1));
com.Parameters.Add(new SqlParameter("@streetname", SqlDbType.VarChar, 50, streetname));
com.Parameters.Add(new SqlParameter("@keyword1", SqlDbType.VarChar, 50, keyword1)); 
com.Parameters[0].Value = lat1;
com.Parameters[1].Value = lng1;
com.Parameters[2].Value = radius1;
com.Parameters[3].Value = streetname;
com.Parameters[4].Value = keyword1;
try
{                
    sqlda.Fill(ds);
    con.Close();
}
catch (Exception e)
{
    con.Close();
}

This is my stored procedure I have written in sql server. It runs successfully in SQL server

USE [Test]
GO
/****** Object:  StoredProcedure [dbo].[tesproc]    Script Date: 09/01/2010 13:00:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
 ALTER PROCEDURE [dbo].[tesproc]
    -- Add the parameters for the stored procedure here
    @a float, @b float, @d int,@s varchar(50),@k varchar(50)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    select Id, Name1,ZipCode,StreetName,StreetNumber,State1,Lat,Lng , ( 6371 * ACOS( COS( (@a/57.2958) ) * COS(  (Lat/57.2958)  ) * COS( ( Lng/57.2958 ) - (@b /57.2958) )  + SIN( @a/57.2958 ) * SIN(  Lat/57.2958  ) ) ) as distance from business_details where (( 6371 * ACOS( COS( (@a/57.2958) ) * COS(  (Lat/57.2958)  ) * COS( ( Lng/57.2958 ) - (@b /57.2958) )  + SIN( @a/57.2958 ) * SIN(  Lat/57.2958  ) ) )<@d and StreetName like '%'+ @s + '%' and Keyword like '%'+ @k +'%')
END
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:35:32+00:00Added an answer on May 16, 2026 at 3:35 pm

    Anyway your code should look like this:

    using (SqlConnection connection = new SqlConnection(connectionString))
    using (SqlComamnd command = connection.CreateCommand())
    {
        command.CommandText = commandText;
        command.CommandType = CommandType.StoredProcedure;
    
        command.Parameters.Add("@lat1", SqlDbType.Float,50, lat1).Value = lat1;
        command.Parameters.Add("@lng1", SqlDbType.Float,50, lng1).Value = lng1;
        command.Parameters.Add("@radius1", SqlDbType.Int,10, radius1).Value = radius1;
        command.Parameters.Add("@streetname", SqlDbType.VarChar, 50, streetname).Value = streetname;
        command.Parameters.Add("@keyword1", SqlDbType.VarChar, 50, keyword1).Value = keyword1;
    
        connection .Open();
        DataSet ds = new DataSet();
        using (SqlDataAdapter adapter = neq SqlDataAdapter(command))
        {
            adapter.Fill(ds);                
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.