I have just found the answer to my 2nd question:
string username = mySystem.CurrentUserName
but I am still struggling with the first. I am thinking of programmatically setting the [User ID] columns Unique property to True...
... And that fails. Instead of creating another row, I get an exception: "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." so it is still trying to create a new row.
You should be able to find plenty of examples for working with DataTables on Microsoft's site. For example: How to: Edit Rows in a DataTable at msdn.microsoft.com/.../tat996zc(v=vs.80).aspx.
Code below is an example of how to modify a row:
myTable.CheckOut(); DataTable myTable = myAFTable.Table; Data.DataRow rows = myTable.Select("User ID='User1'); rows["MyValueColumn1"] = 123; myTable.AcceptChanges(); myAFTable.CheckIn();
I had the same issue at some point. You just need to set a primary key programmatically prior to make your changes. Here's an example: (note that in this example the key is composed of a single field).
Dim myPISystems As New PISystems Dim myPISystem As PISystem = myPISystems.DefaultPISystem Dim myDB As AFDatabase = myPISystems.Item(yourAFServerName).Databases.Item(yourAFDatabase) Dim arPrimaryKey(0) As System.Data.DataColumn arPrimaryKey(0) = myDB.Tables(yourTablename).Table.Columns(yourColumnname) myDB.Tables(yourTablename).Table.PrimaryKey = arPrimaryKey myDB.CheckIn()