OK – I have worded this search 40 different ways and I seem to be lost here.
Every example I find seems so happy that you can easily drag and drop a datagrid and let the user fill it in — then they stop! I know how to do everything I am asking through LINQ. That obviously won’t translate here. I really should have learned ADO.NET first, then LINQ, but NOoooo…
I need to know how to do the following in .NETCF (Windows Mobile 5) using a SQL CE database on the device.
-
Add a new record and populate some or all of the fields with data I supply. I don’t need to add a record to a datagrid – sometimes the user will not even see the record. How do I add a new record — put data into it and save it? For example: Create a new delivery record, say, and have the program store the date in one field and a number in another field.
-
Search for a record, then update data in it. Again, using LINQ I can do this easily — I cannot for the life of me find any examples of doing it without it. I can find lots of examples of populating a grid of databound fields, letting the user make changes then saving it out. I don’t need to do that.
Say I need to search for the one record that meets a criteria (customerID=10 and orderID=1234), then when (if) that record is found, update a field in it.
Please let me know if you need any more info. I have done a lot of reading and just seem to be missing something!
Thanks in advance…
For #1, there are a few ways. Two easy, common ways are:
Use a SqlCeResultset, and create a row with it, then insert.
Use a SqlCeCommand, set the command SQL and call ExecuteNonQuery.
For #2 it’s not much different. Use an updateable resultset, seek to the record, modify and call Update or build your SQL and send it through the command using ExecuteScalar or ExecutNonQuery. The code is similar enough to those above that I’ll leave it to you to work out.
A quick search on ‘SqlCeResultSet’ and ‘example’ or ‘update example’ give loads of relevant results.