简体   繁体   中英

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

    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: '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: ''

Software : 软件镜像

The using clause makes a reference to the namespace of the classes you are using. You also need to add a reference to the dll that the namespace is defined in.

in solution explorer there is a node under your project called Reference . Right click this ans choose Add from the menu. Find System.Data and include that.

If you refer to the MSDN documentation at https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter(v=vs.110).aspx

It tells you the namespace and dll you need.

Namespace: System.Data.SqlClient

Assembly: System.Data (in System.Data.dll )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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