简体   繁体   English

如何在Visual Studio代码中调试C#代码

[英]How to Debug C# code in visual studio code

I want to debug my c# code in vs code but when I run I encountered some errors .and it needs some references.so I add system.data.sqlclient but again it needs reference for SqlDataAdapter .please help me to solve this problem 我想在vs代码中调试我的C#代码,但是运行时遇到一些错误。它需要一些参考。所以我添加了system.data.sqlclient,但它又需要SqlDataAdapter的参考。请帮助我解决此问题

    using System;
using System.Data;
using System.Data.SqlClient;
namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            try
            {     DataTable dt = new DataTable();
                SqlConnection sqlconn = new SqlConnection(DBsetting.Connstring);
                SqlDataAdapter sqlda = new SqlDataAdapter("SelectUserswith", sqlconn);
                sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
                sqlda.SelectCommand.Parameters.AddWithValue("@n", textBox1.Text.Trim());
                dt.Clear();
                sqlda.Fill(dt);
                if (dt.Rows!=null && dt.Rows.Count > 0 && dt.Rows[0]["username"] != null && dt.Rows[0]["Depassword"].ToString() == textBox2.Text.Trim())
                {
                    this.Hide();
                    MenuFrm f1 = new MenuFrm();
                    f1.un = dt.Rows[0]["name"].ToString();
                    f1.uID = dt.Rows[0]["ID"].ToString();
                    f1.username = dt.Rows[0]["username"].ToString();
                    f1.Show();
                }
               else
                {
                    MessageBox.Show("Error");
                }

            }
            catch (Exception ex)
            {


                    MessageBox.Show(ex.Message);

            }
        }
    }
}

Error : 错误:

file: 'file:///c%3A/Users/JAVAD/Documents/SampleVsCode/Program.cs' severity: 'Error' message: 'The type or namespace name 'SqlDataAdapter' could not be found (are you missing a using directive or an assembly reference?)' at: '13,17' source: '' 文件:'file:///c%3A/Users/JAVAD/Documents/SampleVsCode/Program.cs'严重性:'错误'消息:'找不到类型或名称空间名称'SqlDataAdapter'(您是否缺少使用指令还是程序集引用?)”,网址:“ 13,17”,来源:“

file: 'file:///c%3A/Users/JAVAD/Documents/SampleVsCode/Program.cs' severity: 'Error' message: ''DataTable' does not contain a definition for 'Clear' and no extension method 'Clear' accepting a first argument of type 'DataTable' could be found (are you missing a using directive or an assembly reference?)' at: '16,20' source: '' 文件:“ file:///c%3A/Users/JAVAD/Documents/SampleVsCode/Program.cs”严重性:“错误”消息:“ DataTable”不包含“清除”的定义,也没有扩展方法“清除” '可以在以下位置找到接受'DataTable'类型的第一个参数(您是否缺少using指令或程序集引用?)':'16,20'来源:''

Software : 软件: 软件镜像

The using clause makes a reference to the namespace of the classes you are using. using子句引用您正在使用的类的名称空间。 You also need to add a reference to the dll that the namespace is defined in. 您还需要添加对在其中定义了名称空间的dll的引用。

in solution explorer there is a node under your project called Reference . 在解决方案资源管理器中,您的项目下有一个名为Reference的节点。 Right click this ans choose Add from the menu. 右键单击它,然后从菜单中选择“添加”。 Find System.Data and include that. 查找System.Data并将其包括在内。

If you refer to the MSDN documentation at https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter(v=vs.110).aspx 如果您参考https://msdn.microsoft.com/zh-cn/library/system.data.sqlclient.sqldataadapter(v=vs.110).aspx上的MSDN文档

It tells you the namespace and dll you need. 它告诉您所需的名称空间和dll。

Namespace: System.Data.SqlClient 命名空间: System.Data.SqlClient

Assembly: System.Data (in System.Data.dll ) 程序集:System.Data(在System.Data.dll中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM