private void insertDate()
{
da.UpdateCommand = new SqlCommand("UPDATE WaynokaLogger SET Date = @Date", cs);
da.UpdateCommand.Parameters.Add("@Date", SqlDbType.Date).Value = dt;
da.UpdateCommand.ExecuteNonQuery();
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Thx for Voting :(
I will still help you out... what you have to do is to use WHERE clause to specify for which row you want to update the datetime. Do you have any Id, or some other unique column, so you can use the comparison?
Your query them will look:
da.UpdateCommand = new SqlCommand("UPDATE WaynokaLogger SET Date = @Date WHERE YourUniqueColumn = @uniqueColumn", cs);
da.UpdateCommand.Parameters.Add("@Date", SqlDbType.Date).Value = dt;
da.UpdateCommand.Parameters.Add("@uniqueColumn", SqlDbType.Int).Value = SomeUniqueValue;
da.UpdateCommand.ExecuteNonQuery();
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Sure you can update a NULL value in a particular cell. Null only refers there is no data yet in the cell (at least it worked for me), maybe it differs form database to databsse, not sure about it.
If its still doesnt work, try with Insert command.
But insert only that field.
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
Code code it self has to be ok (the strucure I mean) but I dont know about your column names and the conitional clause (where).
Where did you get the where clause and check if it really exist in the database`s table.
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13
You dont need to use ID as Where clause, you can use a name, or lastname, or both or them, or some other field.
But the problem comes, when there are duplicates of names (or lastnames, or whatever field). Thats why we use ID column. Id is (must be) unique, and cannot be duplicated.
That why its strongly recommended to use for a where clause an id field.
But if you want to do an update and use a where clause, you have to know this particular id. You have to get it some how.
Are you able to get it?
If so, there is no problem, if not, you have to think of some way to get it.
Thats why its best to have to dataTable, where are all the fields inside (with all the rows (all the data)), so you have in one row: an id, name, lastname, and other columns.
So when you want to update some date, you get this particular row out, and now you are sure that an Id belongs only to the name and lastname from this row.
And this way you can simply do an update.
You know what I mean?
Read carefully, and try to do some examples, and let me know.
Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13