473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

error in updating records in access db...

vikas1111
122 100+
Hi All..
I am accessing 2 colums from access database and updating them .

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim c As New adodb.Connection
  3. Dim cn As New adodb.Connection
  4. Dim cm As adodb.Command
  5. Dim rsnew2 As New adodb.Recordset
  6.  
  7. Private Sub cmd_edit_Click()
  8.  
  9. If text1.Text = "" Then
  10.     MsgBox " enter the company name"
  11.     text1.SetFocus
  12.     rsnew2.Fields("text1") = text1.Text
  13.  End If
  14. If text2.Text = "" Then
  15.     MsgBox " enter the company address"
  16.     text2.SetFocus
  17.     rsnew2.Fields("text2") = text2.Text
  18.  End If
  19. rsnew2.Update
  20.     MsgBox " add new successful ", vbInformation, "successful"
  21.  
  22. End Sub
  23.  
  24. Private Sub Form_Load()
  25. Dim cs As String
  26. c.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\COMION.MDB;Persist Security Info=False")
  27. rsnew2.Open "select * from company", c, adOpenDynamic
  28. Me.text1.Text = rsnew2(2)
  29. Me.text2.Text = rsnew2(3)
  30.  
  31. End Sub
  32.  
There is error in RSNEW2.UPDATE ..
CAN ANYBODY HELP ME TO SOLVE MY PROBLEM ??????????
Feb 25 '08 #1
23 1789
debasisdas
8,127 Expert 4TB
You need to call AddNew or Edit method of recordset before calling Update.
Feb 25 '08 #2
vikas1111
122 100+
You need to call AddNew or Edit method of recordset before calling Update.
rsnew2.Recordset.AddNew
is it correct???
Feb 25 '08 #3
vikas1111
122 100+
rsnew2.Recordset.AddNew
is it correct???
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim c As New adodb.Connection
  3. Dim cn As New adodb.Connection
  4. Dim cm As adodb.Command
  5. Dim rsnew2 As New adodb.Recordset
  6. Dim rsnew3 As New adodb.Recordset
  7.  
  8.  
  9. Private Sub cmd_close_Click()
  10. Unload.me
  11. End Sub
  12.  
  13. Private Sub cmd_edit_Click()
  14. rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
  15. If text1.Text = "" Then
  16. MsgBox " enter the company name"
  17. text1.SetFocus
  18. rsnew3.Fields("text1") = text1.Text
  19.  End If
  20. If text2.Text = "" Then
  21. MsgBox " enter the company address"
  22. text2.SetFocus
  23. rsnew3.Fields("text2") = text2.Text
  24. End If
  25. rsnew3.Update
  26. MsgBox " add new successful ", vbInformation, "successful"
  27.  
  28. End Sub
  29.  
  30. Private Sub Form_Load()
  31. Dim cs As String
  32. c.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\COMION.MDB;Persist Security Info=False")
  33. rsnew2.Open "select * from company", c, adOpenDynamic
  34. Me.text1.Text = rsnew2(2)
  35. Me.text2.Text = rsnew2(3)
  36.  
  37. End Sub
  38.  
I am getting message that "edit is successful", but its not updating in database..
What should i do ????
Feb 25 '08 #4
debasisdas
8,127 Expert 4TB
try using this

Expand|Select|Wrap|Line Numbers
  1. c.BeginTrans
  2. c.execute "Your update command here"
  3. c.CommitTtans
  4.  
Feb 25 '08 #5
vikas1111
122 100+
try using this

Expand|Select|Wrap|Line Numbers
  1. c.BeginTrans
  2. c.execute "Your update command here"
  3. c.CommitTtans
  4.  

Error invalid sql statement...
Feb 25 '08 #6
debasisdas
8,127 Expert 4TB
Error invalid sql statement...
you need to write a valid sql statmnet .
Feb 25 '08 #7
lotus18
866 512MB
Error invalid sql statement...
You need to specify the table and the fields you want to update.
I think you need learn the basics of sql

Sample

Expand|Select|Wrap|Line Numbers
  1. "Update <TableName> Set <FieldName1>='My 1st Record', <FieldName2>='My 2nd Record', <FieldNameN>='My N Record'"
Remember enclosing with ' for string, # for dates, and nothing (as in nothing) if it is a number type. : )

Feb 25 '08 #8
vikas1111
122 100+
You need to specify the table and the fields you want to update.
I think you need learn the basics of sql

Sample

Expand|Select|Wrap|Line Numbers
  1. "Update <TableName> Set <FieldName1>='My 1st Record', <FieldName2>='My 2nd Record', <FieldNameN>='My N Record'"
Remember enclosing with ' for string, # for dates, and nothing (as in nothing) if it is a number type. : )



I am using Microsoft Access Database.......
Feb 25 '08 #9
debasisdas
8,127 Expert 4TB
I am using Microsoft Access Database.......
kindly post the UPDATE query that you are executing
Feb 25 '08 #10
vikas1111
122 100+
kindly post the UPDATE query that you are executing
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim C As New ADODB.Connection
  3. Dim cn As New ADODB.Connection
  4. Dim cm As ADODB.Command
  5. Dim rsnew2 As New ADODB.Recordset
  6. Dim rsnew3 As New ADODB.Recordset
  7.  
  8.  
  9. Private Sub cmd_close_Click()
  10. Unload.me
  11. End Sub
  12.  
  13. Private Sub cmd_edit_Click()
  14. rsnew3.Open "select * from company", C, adOpenDynamic, adLockOptimistic
  15. If text1.Text = "" Then
  16. MsgBox " enter the company name"
  17. text1.SetFocus
  18. rsnew3.Fields("text1") = text1.Text
  19.  End If
  20. If text2.Text = "" Then
  21. MsgBox " enter the company address"
  22. text2.SetFocus
  23. rsnew3.Fields("text2") = text2.Text
  24. End If
  25. rsnew3.Update
  26. MsgBox " add new successful ", vbInformation, "successful"
  27.  
  28. End Sub
  29.  
  30. Private Sub Form_Load()
  31. Dim cs As String
  32. C.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\COMION.MDB;Persist Security Info=False")
  33. rsnew2.Open "select * from company", C, adOpenDynamic
  34. Me.text1.Text = rsnew2(2)
  35. Me.text2.Text = rsnew2(3)
  36.  
  37. End Sub
Getting message that database has been updated.. but no changes are made ..
Feb 25 '08 #11
debasisdas
8,127 Expert 4TB
I asked you for your UPDATE query .

Refer to my previous post.
Feb 25 '08 #12
vikas1111
122 100+
I asked you for your UPDATE query .

Refer to my previous post.
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Dim C As New ADODB.Connection
  3. Dim cn As New ADODB.Connection
  4. Dim cm As ADODB.Command
  5. Dim rsnew2 As New ADODB.Recordset
  6. Dim rsnew3 As New ADODB.Recordset
  7.  
  8.  
  9. Private Sub cmd_close_Click()
  10. Unload.me
  11. End Sub
  12.  
  13. Private Sub cmd_edit_Click()
  14. rsnew3.Open "select * from company", C, adOpenDynamic, adLockOptimistic
  15. If text1.Text = "" Then
  16. MsgBox " enter the company name"
  17. text1.SetFocus
  18. rsnew3.Fields("text1") = text1.Text
  19.  End If
  20. If text2.Text = "" Then
  21. MsgBox " enter the company address"
  22. text2.SetFocus
  23. rsnew3.Fields("text2") = text2.Text
  24. End If
  25. C.BeginTrans
  26. C.Execute "rsnew3.Update"
  27. C.CommitTtans
  28.  
  29. MsgBox " add new successful ", vbInformation, "successful"
  30.  
  31. End Sub
  32.  
  33. Private Sub Form_Load()
  34. Dim cs As String
  35. C.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\COMION.MDB;Persist Security Info=False")
  36. rsnew2.Open "select * from company", C, adOpenDynamic
  37. Me.text1.Text = rsnew2(2)
  38. Me.text2.Text = rsnew2(3)
  39.  
  40. End Sub
Feb 25 '08 #13
debasisdas
8,127 Expert 4TB
Can't you understand what is a UPDATE query.
Feb 25 '08 #14
lotus18
866 512MB
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_edit_Click()
  2. If text1.Text = "" Then
  3.      MsgBox " enter the company name"
  4.      text1.SetFocus
  5.      Exit Sub
  6. ElseIf text2.Text = "" Then
  7.      MsgBox " enter the company address"
  8.      text2.SetFocus
  9.      Exit Sub
  10. Else
  11.      C.Execute "Update Company Set text1='" & Text1.Text & "', text2='" & Text2.Text & "' Where ID='" & txtID.Text & "'" 
  12.      MsgBox "Update successful ", vbInformation, "successful"
  13. End If
Im assuming that your field names are text1 and text2 (I've based it on your codes) and lastly txtID.Text as your Primary Key (ID Field)

Rey Sean
Feb 25 '08 #15
Killer42
8,435 Expert 8TB
Subscribing .
Feb 26 '08 #16
vikas1111
122 100+
Subscribing .

what???? i couldnt understand...
Feb 26 '08 #17
lotus18
866 512MB
what???? i couldnt understand...
He just wants to subscribe to this thread so that anytime he can go to this thread.
Feb 26 '08 #18
vikas1111
122 100+
He just wants to subscribe to this thread so that anytime he can go to this thread.

Ok this site is new to me so i dont know much about it...
Feb 26 '08 #19
lotus18
866 512MB
Ok this site is new to me so i dont know much about it...
BTW, have you fixed your problem?
Feb 26 '08 #20
vikas1111
122 100+
BTW, have you fixed your problem?
No there is 1 error. I am working on it.
Feb 26 '08 #21
lotus18
866 512MB
No there is 1 error. I am working on it.
Hope you got it right ^ ^ .
Feb 26 '08 #22
Ali Rizwan
925 512MB
HELLO Vikas,
Sorry for late,
This is the sample after doing all open the database you will see the changes.

Regards
>> ALI <<
Attached Files
File Type: zip DBS.zip (8.4 KB, 93 views)
Feb 27 '08 #23
vikas1111
122 100+
Hope you got it right ^ ^ .

Problem finally solved.. Thanks all for helping..


Expand|Select|Wrap|Line Numbers
  1. addnew = True
  2.  
  3. On Error GoTo err1
  4.  
  5. If text1.Text = "" Then
  6.    MsgBox " enter the c name"
  7.    text1.SetFocus
  8.    Exit Sub
  9. End If
  10.  
  11. If text2.Text = "" Then
  12.    MsgBox " enter the c addr"
  13.    text2.SetFocus
  14.    Exit Sub
  15. End If
  16.  
  17. rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
  18. rsnew3.addnew
  19. rsnew3.Fields("comp_name").Value = text1.Text
  20. rsnew3.Fields("comp_addr").Value = text2.Text
  21. rsnew3.Update
  22. rsnew3.Close
  23. If addnew = True Then MsgBox " add new successful ", vbInformation, "successful"
  24.  
  25. If rsnew3.State = adStateOpen Then rsnew3.Close
  26. Set rsnew3 = Nothing
Mar 3 '08 #24

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

Similar topics

12
by: ColinWard | last post by:
Hi. I am trying to run the following code when the user clicks a button, but I am getting a syntax error in the SQL. I have a feeling it has to do with brackets. Can anyone help? here is the...
0
by: crypto_solid via AccessMonster.com | last post by:
I have been using a SQL database with a VB5 frontend for about 5 years. Works well. Unfortunately I don't have access to the source code. I was tasked with implementing a "job entry" application...
4
by: Darrel | last post by:
I'm creating a table that contains multiple records pulled out of the database. I'm building the table myself and passing it to the page since the table needs to be fairly customized (ie, a...
14
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these...
1
by: davidgordon | last post by:
Hi, If I am updating a list of records for a user on an asp page, is there a way to hold the page updating, even if they refresh the page, until I have updated all the records. i.e. rather...
2
by: Alexey.Murin | last post by:
The application we are developing uses MS Access 2003 database (with help of ADO). We have noticed that during massive records updating the size of the mdb file increases dramatically (from 3-4 to...
7
by: Mathew Butler | last post by:
I'm investigating an issue I have when pulling data back from MS access I'm retrieving all rows from a column in a table of 5000 rows - accessing a column of type "memo" ( can be 65353 character...
3
by: amatuer | last post by:
ADODB.Recordset error '800a0cb3' Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype. /devag/newProjSave.asp, line 321 ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.