Hi,
As I can see in your code snippets everything is fine, except
cmd.ExecuteNonQuery
. You can use the ExecuteNonQuery to perform catalog operations (for example, querying the structure of a database or creating database objects such as tables), or to change the data in a database without using a DataSet by executing
UPDATE
,
INSERT
, or
DELETE
statements. Although the ExecuteNonQuery returns no rows, any output parameters or return values mapped to parameters are populated with data.. Remove it from your code. It'll work properly. Try this:
SqlConnection con = new SqlConnection(@"Data Source=Desk\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("Select * from Customers", con);
SqlDataAdapter da = new SqlDataAdapter(cmd, con);
da.Fill(dt);
All the best.
--Amit