Visual Studio Community 2017不支持ADO.NET? [英] ADO.NET not supported in Visual Studio Community 2017?

查看:158
本文介绍了Visual Studio Community 2017不支持ADO.NET?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


    我是Visual Studio Community Edition 2017的新手,我已经处理过旧版本的Visual Studio,但是这个版本并没有识别ADO.NET。我创建了一个控制台应用程序并使用System添加了以下代码

; 
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;
// NC-1更多名称空间。
使用System.Data.SqlClient;
使用System.Configuration;
名称空间CaseTrackerAlerts
{


///< summary>
///演示如何使用SqlConnection对象
///< / summary>
class SqlConnectionDemo
{
static void Main()
{
// 1.实例化连接
SqlConnection conn = new SqlConnection(
"Data Source = 10.32.35.54; Initial Catalog = CaseTracker; Integrated Security = SSPI");

SqlDataReader rdr = null;

尝试
{
// 2.打开连接
conn.Open();

// 3.将连接传递给命令对象
SqlCommand cmd = new SqlCommand(" select * from Customers" conn);

如果缺少程序集引用,它会一直说不能找到类型或命名空间。请帮助。



问候,


布莱恩

解决方案

让父亲System.Data在项目参考中,例如



然后你需要的是

使用System.Data .SqlClient; 

namespace ConsoleApp4
{
class program
{
static void Main(string [] args)
{
using( SqlConnection cn = new SqlConnection(){ConnectionString =" TODO"})
{
using(SqlCommand cmd = new SqlCommand(){Connection = cn,CommandText =" TODO"})
{
cn.Open();
}
}
}
}
}


Hi,

     I'm new to Visual Studio Community Edition 2017, I've dealt with older versions of Visual Studio but this one is not recognizing ADO.NET. I created a console app and added the following code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//NC-1 More namespaces.  
using System.Data.SqlClient;
using System.Configuration;
namespace CaseTrackerAlerts
{


    /// <summary>
    /// Demonstrates how to work with SqlConnection objects
    /// </summary>
    class SqlConnectionDemo
    {
        static void Main()
        {
            // 1. Instantiate the connection
            SqlConnection conn = new SqlConnection(
                "Data Source=10.32.35.54;Initial Catalog=CaseTracker;Integrated Security=SSPI");

            SqlDataReader rdr = null;

            try
            {
                // 2. Open the connection
                conn.Open();

                // 3. Pass the connection to a command object
                SqlCommand cmd = new SqlCommand("select * from Customers", conn);

It keeps saying the type or namespace can't be found are you missing an assembly reference. Please help.

Regards,

Bryan

解决方案

Make sire System.Data is in the project references e.g.

Then all you should need is

using System.Data.SqlClient;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SqlConnection cn = new SqlConnection() { ConnectionString = "TODO" })
            {
                using (SqlCommand cmd = new SqlCommand() { Connection = cn, CommandText = "TODO" })
                {
                    cn.Open();
                }
            }
        }
    }
}


这篇关于Visual Studio Community 2017不支持ADO.NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆