[Solved] An unhandled exception of type ‘System.InvalidOperationException’ occurred in System.Data.dll?


You should either use this method:

SqlCommand cmd = new SqlCommand("dbo.workScheduleDataGrid", sqlcon);

or this method

SqlCommand cmd = sqlcon.CreateCommand();

to create the command, but not both (the second assignment in your code overwrites the first one).

With the second options, you need to specify the command to execute separarely:

cmd.CommandText = "dbo.workScheduleDataGrid";

Also, do not forget to dispose the cmd object, best with another using statement.

solved An unhandled exception of type ‘System.InvalidOperationException’ occurred in System.Data.dll?