Problem loading a table with SQL data in c #

0

I'm creating a web page and I want to show a table with saved data from that same table on a SQL server. For now I have this:

public partial class historyTable : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    private void btnCargar_Click(object sender, EventArgs e)
    {
        System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection("server=NameServer;uid=team;" +
          "pwd=contraseña;database=BaseDeDatos; Initial Catalog=history;Integrated Security=true;");

        cn.Open();
        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand("SELECT * FROM history", cn);
        System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        dataGridView1.DataSource = dt;
        cn.Close();
    }
}

I'm trying to show the data in the "history" table but it says that I have a bug in dataGridView1.DataSource = dt; and dn cn.Close ()

Thank you.

    
asked by user5673573 19.03.2018 в 22:04
source

1 answer

0
   System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection("DataSource=/*Aqui*/; Initial Catalog=history;Integrated Security=true;");

The first thing you should do is the following where you put the comment here you must put the name of the follower then separated by backslashes to put the name of the server, that is, it would be like this

"Data Source=TEST\SQL2008;Initial Catalog=GPIND;User ID=sa;Password=1234"
    
answered by 19.03.2018 в 22:55