473,698 Members | 2,556 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update <table Name> Set <fields> where condition

1 New Member
Hi
I am new to visual basic. I write program to navigate & update data from table.
My database is in Informix & use ODBC connection. When I nevigate the data it works properly. When I Update the record its also updated but after that if I try to navigate it its giving error "Row cannot be located for updating. Some values may have been change since it was last read". My code is as follows -

Option Explicit
Dim cnn As Connection
Dim WithEvents rs As Recordset
Dim stmt As String
Dim sql As String
Dim mm_rec As Integer
Dim mm_cnt As Integer


Private Sub cmdDel_Click()
On Error GoTo errdel
Dim txtmsg As Integer
txtmsg = MsgBox("This will Delete Record From MASTER", vbOKCancel, "WARNING")
If txtmsg = 1 Then
sql = "delete from masters where ma_trcd = '" & txtFields(0) & "' and ma_code = '" & txtFields(1) & "' "
cnn.Execute sql

MsgBox "Record Deleted Successfully !!"
Exit Sub
Else
stBar.Panels(3) .Text = "DELETE ABORT"


Exit Sub
End If
errdel:
MsgBox "Can Not Delete Record Check Error "
End Sub

Private Sub cmdExit_Click()
cnn.Close
Unload Me
End Sub
Private Sub disprecno()
stBar.Panels(3) .Text = "Record : " & CStr(rs.Absolut ePosition)
End Sub


Private Sub cmdNext_Click()
On Error GoTo errnext
If Not rs.EOF Then rs.MoveNext
disprecno

If rs.EOF Then
rs.MoveLast
MsgBox "This Is Last Record !!!"
End If
Exit Sub
errnext:
MsgBox Err.Description
End Sub
Private Sub rs_MoveComplete (ByVal adReason As ADODB.EventReas onEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStat usEnum, ByVal pRecordset As ADODB.Recordset )

stBar.Panels(3) .Text = "Record: " & CStr(rs.Absolut ePosition)
End Sub
Private Sub cmdPrevious_Cli ck()
On Error GoTo errpr
If Not rs.BOF Then rs.MovePrevious
disprecno

If rs.BOF And rs.RecordCount > 0 Then
rs.MoveFirst
MsgBox "This Is First Record !!!"
End If
Exit Sub

errpr:
MsgBox Err.Description
End Sub

Private Sub cmdUpdate_Click ()
On Error GoTo errupdt
sql = "update masters set ma_name = '" & txtFields(2) & "' where ma_trcd = '" & txtFields(0) & "' and ma_code = '" & txtFields(1) & "'"
cnn.Execute sql

MsgBox "Record Updated Successfully !!"
Exit Sub
errupdt:
MsgBox Err.Description

End Sub

Private Sub Form_Load()
Set cnn = New Connection
cnn.ConnectionS tring = "Provider=MSDAS QL.1;Persist Security Info=False;User ID=lmdbs;Data Source=inf"
cnn.CursorLocat ion = adUseClient

cnn.Open
stmt = "select ma_trcd,ma_code ,ma_name from masters order by ma_trcd"
Set rs = New Recordset
rs.Open stmt, cnn, adOpenDynamic, adLockOptimisti c

Dim oText As TextBox
mm_cnt = rs.AbsolutePosi tion

For Each oText In Me.txtFields
Set oText.DataSourc e = rs
Next

End Sub


Can anyone help me in this.
Thax
Komal
Oct 12 '06 #1
1 5709
willakawill
1,646 Top Contributor
Hi
I am new to visual basic. I write program to navigate & update data from table.
My database is in Informix & use ODBC connection. When I nevigate the data it works properly. When I Update the record its also updated but after that if I try to navigate it its giving error "Row cannot be located for updating. Some values may have been change since it was last read". My code is as follows -

Option Explicit
Dim cnn As Connection
Dim WithEvents rs As Recordset
Dim stmt As String
Dim sql As String
Dim mm_rec As Integer
Dim mm_cnt As Integer


Private Sub cmdDel_Click()
On Error GoTo errdel
Dim txtmsg As Integer
txtmsg = MsgBox("This will Delete Record From MASTER", vbOKCancel, "WARNING")
If txtmsg = 1 Then
sql = "delete from masters where ma_trcd = '" & txtFields(0) & "' and ma_code = '" & txtFields(1) & "' "
cnn.Execute sql

MsgBox "Record Deleted Successfully !!"
Exit Sub
Else
stBar.Panels(3) .Text = "DELETE ABORT"


Exit Sub
End If
errdel:
MsgBox "Can Not Delete Record Check Error "
End Sub

Private Sub cmdExit_Click()
cnn.Close
Unload Me
End Sub
Private Sub disprecno()
stBar.Panels(3) .Text = "Record : " & CStr(rs.Absolut ePosition)
End Sub


Private Sub cmdNext_Click()
On Error GoTo errnext
If Not rs.EOF Then rs.MoveNext
disprecno

If rs.EOF Then
rs.MoveLast
MsgBox "This Is Last Record !!!"
End If
Exit Sub
errnext:
MsgBox Err.Description
End Sub
Private Sub rs_MoveComplete (ByVal adReason As ADODB.EventReas onEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStat usEnum, ByVal pRecordset As ADODB.Recordset )

stBar.Panels(3) .Text = "Record: " & CStr(rs.Absolut ePosition)
End Sub
Private Sub cmdPrevious_Cli ck()
On Error GoTo errpr
If Not rs.BOF Then rs.MovePrevious
disprecno

If rs.BOF And rs.RecordCount > 0 Then
rs.MoveFirst
MsgBox "This Is First Record !!!"
End If
Exit Sub

errpr:
MsgBox Err.Description
End Sub

Private Sub cmdUpdate_Click ()
On Error GoTo errupdt
sql = "update masters set ma_name = '" & txtFields(2) & "' where ma_trcd = '" & txtFields(0) & "' and ma_code = '" & txtFields(1) & "'"
cnn.Execute sql

MsgBox "Record Updated Successfully !!"
Exit Sub
errupdt:
MsgBox Err.Description

End Sub

Private Sub Form_Load()
Set cnn = New Connection
cnn.ConnectionS tring = "Provider=MSDAS QL.1;Persist Security Info=False;User ID=lmdbs;Data Source=inf"
cnn.CursorLocat ion = adUseClient

cnn.Open
stmt = "select ma_trcd,ma_code ,ma_name from masters order by ma_trcd"
Set rs = New Recordset
rs.Open stmt, cnn, adOpenDynamic, adLockOptimisti c

Dim oText As TextBox
mm_cnt = rs.AbsolutePosi tion

For Each oText In Me.txtFields
Set oText.DataSourc e = rs
Next

End Sub


Can anyone help me in this.
Thax
Komal
Your problem is that you are deleting a record in the database using your connection, cnn. Your recordset, rs, is not updated bythe database. It is holding the records that you selected in memory. The conflict is that the record you are trying to navigate to or from is no longer in the database but it is referenced in the recordset.

To avoid this problem you can do one of two things.
a. Never use global recordsets. always declare a new one in each sub
b. Use the recordset to delete the record:

rs.Delete adAffectCurrent
rs.Update
Oct 12 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4331
by: Paul Scotchford | last post by:
Env : SLQSERVER2000 - DTS I want to import a text file with 3 fields in it ... F1: Ident char(3) F2: Note (Text) char(32,000) yeah big eh! F3: Date Field F2: has <CR><LF> thru it, this means the DTS import thinks its a multiple records to deal with as each row is also delimited by <CR><LF>,
5
13118
by: Jonathan Daggar | last post by:
Hello, I'm trying to put together a form with a very tight table formatting. However, every time I put an text-type input field in, the browser pads the area to the right of it with space. I've tried to eliminate it several ways, but it won't go away. It looks like it's forcing at least one space (line break?) in after each field, and then there's some mystery padding on the right that also refuses to go away. I've put up a demo of...
61
24479
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will 'stretch'</td> <td valign="top" width="300">some data that won't 'stetch'</td> </tr> </table>
2
11227
by: js | last post by:
I have a table rendered with XSLT. The first column has a radio button controls for user to make a selection for a particular row. All the values in the remaining columns are all concated with a &#xA0; (blank). I need to retieve the text in each cell of that row if the radio button on that row is clicked. Each <TD> has a numeric ID so that I can use it with document.getElementById().innerText method. I use Javascript to assign some...
6
4648
by: Joe Morrison | last post by:
By my reading of the HTML standard: http://www.w3.org/TR/REC-html40/struct/tables.html the HTML shown below should display the text "Enter password" with the input field immediately adjacent, since the first column uses the "0*" proportional width attribute to request minimum column width. This example works perfectly if viewed with Mozilla/Firefox, but under Internet Explorer, Safari, and Opera it displays with lots of
2
3974
by: RBohannon | last post by:
I had some help on this one earlier, but I'm still having a bit of trouble. I'm sure it's something simple that I just don't know. I'm using Access2000. I have one table with employee salary information. I need to calculate the bi-weekly gross pay (BWG) for each employee. The BWG is slightly different for leap years. As the BWG will have to be adjusted at the beginning and end of every leap year, I want to be able to update all...
2
4843
by: Frank van Vugt | last post by:
Hi, Not exactly a showstopper, but I noticed this behaviour: db=# create table f1 (id int, value int); CREATE TABLE db=# insert into f1 select 1 as id, null; INSERT 25456306 1
5
1664
by: Steven | last post by:
I have the following in my web.config: <system.web> <profile defaultProvider="MyASPSqlProfileProvider" enabled="true" > <properties> <add name="FirstName" defaultValue="" type="string"/> <add name="MiddleInitial" defaultValue="" type="string" /> <add name="LastName" defaultValue="" type="string"/> <add name="Address1" defaultValue="" type="string"/> <add name="Address2" defaultValue="" type="string"/> <add name="City" defaultValue=""...
2
2204
by: jessy | last post by:
I have a table at which i need to add fields in it whenever the user clicks on the Add button , here's my trial but seems sth is wrong : function AddTool() { formdiv = document.getElementById('1'); formdiv.innerHTML = formdiv.innerHTML +'<td align='center'><a href='#'><img border='0' src='../images/delete.gif'></td> '; } thats the Js function and thats the table which is generated through looping:
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.