i can't use sql in winform c#

aley123 1 Reputation point
2022-05-26T00:58:31.467+00:00

Severity Code Description Project File Line Suppression State
Error CS1069 The type name 'SqlConnection' could not be found in the namespace 'System.Data.SqlClient'. This type has been forwarded to assembly 'System.Data.SqlClient, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly. QuanLyNhanVien C:\Users\hosys\OneDrive\Documents\winformc#\QuanLyNhanVien\Form1.cs 16 Active

Windows for business | Windows Server | User experience | Other
Developer technologies | C#
{count} votes

2 answers

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2022-05-26T07:33:21.647+00:00

    If this looks like what you have than double click on the project file in Solution Explorer and add the following, save.

    <ItemGroup>  
    	<PackageReference Include="System.Data.SqlClient" Version="4.8.3" />  
    </ItemGroup>  
    

    Add a using statement for the class or form for working with data.

    using System.Data.SqlClient;  
    

    205728-figure1.png

    1 person found this answer helpful.

  2. Limitless Technology 44,766 Reputation points
    2022-05-31T07:33:09.127+00:00

    Hi there,

    You should install the NuGet package in your project first. If you don't, Visual Studio's Intellisense will still work when you add the using but you won't be able to use it's types in your code.

    -Right Click on your project file in the solution panel, and then Click on the Manage NuGet Packages option.
    -In the NuGet Package Manager window, Select the BrowserRight Click on your project file in the solution panel, and then Click on the Manage NuGet Packages option.
    -Select the first option, System.Data.SqlClient by Microsoft Click on the install button wait for the installation to complete.


    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments

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.