[2008] SQL Command, delete all values in a column, in a table
I have seen this sort of code:
Dim del As New SqlCommand("DELETE FROM Table1")
or
Dim del As New SqlCommand("DELETE FROM Table1 WHERE ID = 3")
(Delete From is the same as Delete * From as I have read in my tutorial)
but I want to do this:
Dim del As New SqlCommand("DELETE FROM Table1 IN COLUMN stringValues")
So it delete's all items added to stringValues.
Can anyone help me with this, I have searched for this with no success.
Cheers
Re: [2008] SQL Command, delete all values in a column, in a table
You don't DELETE values from columns. A DELETE statement deletes rows. If you want to change a field value then you UPDATE that row and set that field. If you don't want a field to contain a value then you set it to NULL.
Re: [2008] SQL Command, delete all values in a column, in a table
So let me get this right?
DataTable contains rows, and rows contain columns (aka data fields?)
Do I have that right?
Re: [2008] SQL Command, delete all values in a column, in a table
I've already explained that in a previous thread of yours. If you don't know how a DataTable works then go to the MSDN Library and read the documentation for the DataTable class.
That's not necessarily relevant to this question anyway. If you want to execute an UPDATE statement against every and set a particular field to the same value in each then there's no need for a DataTable. You don't need to retrieve any data so what would the DataTable be for?
Re: [2008] SQL Command, delete all values in a column, in a table
ugh, I have read the documentation for DataTables and stuff.
I just don't see visually in my head the relationship between table, column, and row.
To me, Table contains columns, and column contains rows, so when I do
Dim sqlCommand("SELECT preferences_value FROM myTable")...
I think in my mind, that that will select all rows in the column preferencs_value, but I don't understand which row is selected?
Do you see how confused I am.
If anyone could explain to me how this works in a very basic manner.
Cheers
Re: [2008] SQL Command, delete all values in a column, in a table
What does this even mean?
Quote:
I think in my mind, that that will select all rows in the column preferencs_value, but I don't understand which row is selected?
You say you think that that column of all rows is selected, which is correct. You then say you don't understand which row is selected. You just said yourself that they all are. When that query is executed it retrieves the only the specified column of every row in the table and populates a DataTable with that data. Therefore you will end up with a DataTable with one column and N rows where N is the number of rows in the table in the database. If you'd executed the query you could have examined the DataTable to see how many columns and rows it had, and the properties of each.
Re: [2008] SQL Command, delete all values in a column, in a table
Okay, thanks I see now.
Cheers
Re: [2008] SQL Command, delete all values in a column, in a table
I think in short, the SQL command you're looking for is:
Dim del As New SqlCommand("UPDATE Table1 SET stringValues = NULL;")