I am trying the following in order to display the sql table data inside a gridview
try
{
SqlConnection xconn = new SqlConnection();
xconn.ConnectionString = @"Data Source=servername;Integrated Security=True;Initial Catalog=master";
xconn.Open();
string s = "select * from tablename";
SqlCommand ycmd = new SqlCommand(s,xconn);
SqlDataReader dr = ycmd.ExecuteReader();
gridview.DataSource = dr;
gridview.DataBind();
}
catch (Exception)
{
lblresult.Text = "Cannot connect to SQL";
}
I keep getting an exception. What am i doing wrong?