Question Data View

shahjehan

New member
Joined
Apr 21, 2009
Messages
1
Programming Experience
Beginner
I have set a condition that if this record is not in database then insert record otherwise update record.
.
.
.
MyScmd3 = New OleDbCommand("select count(*) from PL_Stat where CompanyID=" & Ins_Com & " and PeriodID=" & Ins_Per & " and eYear=" & Ins_Year & "", MyODbC)

MyAdap3 = New OleDbDataAdapter(MyScmd3)
MyDSet3.Clear()
MyAdap3.Fill(MyDSet3)
MyDViw3 = New DataView(MyDSet3.Tables(0))

MyODbC.Open()
If MyDViw3.Count = 0 Then

'MYDViw3 show value 1 even though there is no already same record which i want to save.

'It should show value 0.
.
.
.
.
 
Read the DW2 link in my signature, starting with the section on Creating a Simple Data App.. Once you know how to do data access properly, the following can be achieved in about 5 lines of code:

Try
Insert the record
Catch a failure (primary key violation)
Update the record
End Try


If you think that more than 50% of the time the row WILL be there, it makes more sense to do this:

Try
Update the record
Catch a failure (row does not exist)
Insert the record
End Try
 

Latest posts

Back
Top