相关文章推荐
安静的人字拖  ·  Swagger中的对象列表·  1 月前    · 
安静的人字拖  ·  详解C# ...·  7 月前    · 
安静的人字拖  ·  push() / Reference / ...·  10 月前    · 
眼睛小的匕首  ·  Java.lang.NullPointerE ...·  19 分钟前    · 
任性的斑马  ·  Java org apache-阿里云·  19 分钟前    · 
威武的罐头  ·  ecs/ec2 ...·  2 小时前    · 
激动的书包  ·  Excel ...·  2 小时前    · 
任性的蘑菇  ·  Dictionary<tkey> 类 ...·  2 小时前    · 

I did a clean install of Windows 11 then installed Visual studio 2022 for .NET desktop environment (C@, Visual Basic, F# with NET and NET Framework). Then I created a project of type windows forms app (.net windows forms (winforms) app) with C# filter. I loaded code from an existing project from VS 2019. It was public Microsoft.Data.SqlClient.SqlConnection dbConn; but I changed to public System.Data.SqlClient.SqlConnection dbConn;
I get this 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.
I tried looking at Nuget and found nothing. I also looked at Solution Explorer and there are no references. How can I fix this error?

Then I created a project of type windows forms app (.net windows forms (winforms) app) with C# filter.

You probably created a .NET Core project
Create a .NET Framework project

(or add the System.Data.SqlClient NuGet package for .NET Core)

There are two different packages where each have various versions which are installed via NuGet using manage NuGet packages or the command line in Visual Studio.

https://www.nuget.org/packages/System.Data.SqlClient/

https://www.nuget.org/packages/Microsoft.Data.SqlClient/

Have no clue about filter its too wide of a topic.

If you double click the project in Solution folder add the following and save. Visual Studio will install the package for you.

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

I have fixed the problem.
There are dependencies but no references in solution explorer, right click on project node brings up csproj file
which has <TargetFramework>net6.0-windows</TargetFramework>
In the top level menu under project tab is add reference.
Right click on project node has add\project references in the drop down menu. Has projects, shared projects, COM, Browse.
I used Browse and tried to add a reference to C:\Windows\Microsoft.NET\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089 but it was invalid
.net 6.0 doesn't have System.Data.SqlClient. it is in .net platform extensions 6.
Downloaded and ran MS compatability pack. Then ran nuget package manager and installed System.Data.SqlClient. Now it compiles with 0 errors,

 
推荐文章