Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FillSchema and Identity column
Message
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00740181
Message ID:
00740693
Views:
21
Hi Cathi,

I too, am using the identity fields.

all table fields are interger

Listing Table Client Table
------------------ --------------------
FileNum - Identity ClientNum - Identity
ClientNum FileNum

Controls in Form Binding
tbFileNum = Listing - FileNum Textbox
tbClientNum = Listing - ClientNum Textbox

tbClientFileNum = Client - FileNum Textbox

Process
Insert New Listing Row
Insert New Client Row
Update New Listing Row ClientNum field with New Client Num

I need to supply the New Row Listing - FileNum field to the Client Table before inserting the New Client Row into the Client Table.

Than I need to supply the New Row Client - ClientNum field to update the New Row Listing - ClientNum field.

The code is a follows:

'----Insert New Listing Row
Me.BindingContext(Listing01_Ds1, "Listing").EndCurrentEdit()
Me.SqlDaListing.Update(Listing01_Ds1, "Listing")
If bAddMode Then
'----Supply new value to Client - FileNum field before Insert New Client
SqlInsertCommand2.Parameters("@FileNum").Value = CInt(teFileNum.Text)
End If

'----Insert New Client Row
Me.BindingContext(Listing01_Client_Ds11, "Client").EndCurrentEdit()
Me.SqlDaClient.Update(Listing01_Client_Ds11, "Client")
If bAddMode Then
'----Retrieve Client Num from Client ds after Inserting New Client Row
Dim strClientNum As String
strClientNum = CType(Listing01_Client_Ds11.Tables("Client").Rows(iCurrRow).Item("ClientNum"), String)
tbClientNum.Text = strClientNum

'----Update Listing Row Again with New Client Number
Me.BindingContext(Listing01_Ds1, "Listing").EndCurrentEdit()
Me.SqlDaListing.Update(Listing01_Ds1, "Listing")
End If

Will this work or is there another (better) way to accomplish this update/insert?

Thanks
Roland

=========================================================================

>Hi Don,
>
>After you retrieve the schema information, you can "tweak" some properties it set for your DataColumns. There are properties that are set for autoincrementing (called AutoIncrement) and read-only (called ReadOnly). For your primary key, just reset each of these to false.
>
>>I'm writing a generic WinForms routine to insert a record, then return the @@identity value and store it back to the current row, so I can then add child records with the correct parent PK.
>>
>>I have an OnRowUpdated procedure that figures out the Primary Key for the current datatable using the "DataTable.PrimaryKey" property.
>>
>>To do this I had to retrieve the datatable schema using this command:
>>
>> DataAdapter.MissingSchemaAction() = MissingSchemaAction.AddWithKey
>>
>>Now I indeed can figure out Primary Key field for the current table. But now I am getting a "Field is read-only" when I try to store the returned @@IDENTITY value back into the table. Before using the MissingSchemaAction I could store a value but couldn't determine the PK field! Kind of a catch-22 so far!
>>
>>Does anyone know the way to return and store an @@identity value for a table using a generic routine that figures out the PK field programmatically? I'm trying to avoid hard-coding the insert for every table.
>>
>>Note: It's interesting that with "MissingSchemaAction.AddWithKey" in effect I DO get a local auto-incrementing field value now, but it's NOT in synch with the server's current value, so the functionality appears useless. In other words, if other user's add records to the server while I'm working locally my local "autoincrement" fields are duplicate IDs, so I can't use the values to create child records. So I do the "SELECT @@IDENTITY" in my OnRowUpdated to retrieve the server's value.
>>
>>Any advice is appreciated!
>>
>>TIA
>>Don Meuse
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform