This line is wrong
objdatarowcollection = objDataTable.Select("student Id =");
First, a field name with spaces requires square brackets around it.
Second, the Select method expects a syntax like you use in the sql WHERE statements. Thus, after the equals, you need a value to filter the row collection
objdatarowcollection = objDataTable.Select("[student Id] =" + someValueToSearchFor);
Said that, your question is still unclear. What do you mean with "Remove Column"? You remove a column removing it from the DataTable in which it exists
For example:
objDataTable.Columns.Remove("ColumnName");
Instead your code tries to delete the row at index 0 of the returned collection of row from the Select method, so if you want to remove a column:
objDataTable.Columns.Remove("C2");
+------+-----+------+ +------+------+
| c1 | c2 | c3 | | c1 | c3 |
+------+-----+------+ +------+------+
| A | D | G | Remove a column named c2 | A | G |
+------+-----+------+ result is +------+------+
| B | E | H | | B | H |
+------+-----+------+ +------+------+
| C | F | I | | C | I |
+------+-----+------+ +------+------+
if you want to delete a row at index 0 of the returned collection
(Notice that if the value to search for is a string you need quotes around the value)
objdatarowcollection = objDataTable.Select("C3 ='H'");
objdatarowcollection[0].Delete();
+------+-----+------+ +------+-----+------+
| c1 | c2 | c3 | | c1 | c2 | c3 |
+------+-----+------+ +------+-----+------+
| A | D | G | Delete a ROW with value | A | D | G |
+------+-----+------+ 'H' in column c3 results in +------+-----+------+
| B | E | H | | C | F | I |
+------+-----+------+ +------+-----+------+
| C | F | I |
+------+-----+------+
Keep in mind that here the words "remove/delete" are virtual.
The DataTable is an in memory object. Deleting elements from the in-memory row collection or removing from the column collection doesn't delete/remove anything in the database physical structure. For that you need real sql queries and the support of the ADO.NET provider of your database engine.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…