How to get rid of the red lines?

BenTam 1,781 Reputation points
2023-03-31T14:38:23.0933333+00:00

Dear All,

The following code is copied from a webpage. How to get rid of the red lines?

StoreProcedure

Developer technologies | C#
{count} votes

Accepted answer
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2023-04-01T08:50:05.7+00:00

    Here is what will work

    Project file

    <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    	<OutputType>Exe</OutputType>
    	<TargetFramework>net6.0</TargetFramework>
    	<ImplicitUsings>enable</ImplicitUsings>
    	<Nullable>enable</Nullable>
    </PropertyGroup>
    <ItemGroup>
    	<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.0" />
    </ItemGroup>
    

    Code

    using System.Data;
    using Microsoft.Data.SqlClient;
    
    namespace AutomationApp;
    
    internal class Program
    {
    
        static void Main(string[] args)
        {
            RunStoredProc();
        }
    
        private static void RunStoredProc()
        {
            using var conn = new SqlConnection() { ConnectionString = "TODO" };
            using var cmd = new SqlCommand("SelectAllTrainers",conn)
            {
                CommandType = CommandType.StoredProcedure
            };
            conn.Open();
            cmd.ExecuteNonQuery();
        }
    }
    

1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2023-03-31T17:58:28.98+00:00

    Are you using .NET Core 7? If not the first line for the connection needs to be a using statement not a using declaration.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.