I have a question. I’ve tried to solve it all day long and I am really stuck. I’m using VS2010 and SQL Server 2012 (quite a bad combination) and I’m trying to execute a fairly simple piece of C# and ASP.net code which goes like this:
string conn = ConfigurationManager.ConnectionStrings["BazaConnectionString"].ConnectionString;
SqlConnection connect = new SqlConnection(conn);
SqlDataAdapter sqlAdapter = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("SELECT * FROM Seminar", connect);
sqlAdapter.SelectCommand = cmd;
DataTable tablica = new DataTable();
sqlAdapter.Fill(tablica);
GridView1.DataSource = tablica;
GridView1.DataBind();
The problem is my gridview is always empty. I have data in the table and SELECT * should select all of it but I get an empty table returned. I’ve been trying Dataset and DataTable but nothing seems to work. Any help is appreciated. Thanks in advance.
I have a hunch that you might be running into an exception – possibly a timeout – and you’re not dealing with this properly…
Try something like this:
If you execute this code – do you happen to fall into the
catchblock? If so: what’s the exception? What does it tell you?