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.