duplicate row values in same table?
Posted on 2005-03-15
what i am trying to do is copy all of the column values from the current row filtered in the dataview to a new row in the same datatable and change the primary key and a few other column values and store it as a new row and insert it into the same table. When i do this with the code below i get a exception thrown saying that this row already exsists in this table even though the primary key("quote_id") is different. Its right its the same row but different and i tested to make sure its changing the quote id and incrementing properly and all so im lost on this one :( I was looking at the importrow method but that will only import to a different datatable. Any help will be greatly appreciated ty!
Public Function FormatQuoteId(ByVal CustId As String, ByVal NextQuoteNum As Integer) As String
Dim myQuoteNum As String = NextQuoteNum.ToString + ""
While myQuoteNum.Length < 3
myQuoteNum = "0" & myQuoteNum
myQuoteNum = CustId & "-" & myQuoteNum
Public Sub DuplicateQuote()
Dim myQuoteIdx As Integer = BindingContext(myDs, "quotes").Position
Dim myChild As Object = myQuoteDv.Item(myQuoteIdx).CreateChildView("quotes_to_customers_via_cust_id").Item(myQuoteIdx)
Dim myCustID As String = cNull(myChild("cust_id"), "String")
Dim myNextNum As Integer = cNull(myChild("next_quote_number"), "Integer")
Dim myNew As DataRow = myDs.quotes.NewquotesRow
Dim newQuoteId As String = FormatQuoteId(myCustID, myNextNum)
myNew = myQuoteDv.Item(myQuoteIdx).Row
myNew("seq") = 0
myNew("cust_id") = myCustID
myNew("quote_id") = newQuoteId
myNew("quote_date") = Date.Now.Today.ToShortDateString
myNew("is_contract") = False
myNew("total_building_cost_override") = myNull
myNew("checked_out") = False
tmpFilter = "quote_id = '" & newQuoteId & "'"
myChild("next_quote_number") = myNextNum + 1