Welcome to dbFreaks.com!
FAQFAQ   SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

adding records into a database using vb

 
   Database Help (Home) -> Visual Basic RSS
Next:  Locale  
Author Message
user3614

External


Since: Jan 31, 2005
Posts: 30



(Msg. 1) Posted: Tue Feb 08, 2005 12:40 pm
Post subject: adding records into a database using vb
Archived from groups: comp>lang>basic>visual>database (more info?)

hi,

i have created a little form to add records into an existing database. the
code looks correct, as follows;

Dim Assignment2 As Connection
Dim rs As Recordset

Private Sub cmdAddRecord_Click()
Dim i As Integer
Set db1 = New ADODB.Connection
db1.Provider = "Microsoft.Jet.OLEDB.4.0;"
db1.ConnectionString = "..."
db1.Open
Dim ar As ADODB.Recordset
Set ar = New ADODB.Recordset

ar.Open "select * from submission_info", Assignment2, adOpenDynmic,
adLockOptimistic

ar.AddNew
ar!Title = txtFirstName.Text
ar!contact_author_first_name = txtFirstName.Text
ar!contact_author_second_name = txtSecondName.Text
ar!contact_author_address_1 = txtInstitute.Text
ar!contact_author_address_2 = txtNameOfInstitute.Text
ar!contact_author_address_3 = txtAddress.Text
ar!contact_author_address_4 = txtCity.Text
ar!contact_author_address_5 = txtCountry.Text
ar!contact_author_address_6 = txtZipCode.Text
ar!paper_ID = txtPaperID.Text
ar!paper_title = txtPaperTitle.Text
ar.Update
End Sub

but when i run the code and click on add, i get an error sayding 'the
connection cannot be used to perform this operation. it is either closed or
invalid in this context'.

i've created a similar form like this, but with only 4 fields, and it works
perfectly. wat am i doing wrong? how can i fix this?

thanx

devin

 >> Stay informed about: adding records into a database using vb 
Back to top
Login to vote
Michael B. Johnson

External


Since: May 14, 2004
Posts: 16



(Msg. 2) Posted: Tue Feb 08, 2005 2:20 pm
Post subject: Re: adding records into a database using vb [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Tue, 08 Feb 2005 17:02:19 GMT, "Devin Panchal"
<d.panchal RemoveThis @ntlworld.com> wrote:

 >ar.Open "select * from submission_info", Assignment2, adOpenDynmic,
 >adLockOptimistic

Your code has syntax errors. I recommend that you copy and paste from
the IDE, including the precise connection string.

 >i've created a similar form like this, but with only 4 fields, and it works
 >perfectly. wat am i doing wrong? how can i fix this?

Other ideas are indexes - some providers require that a PK be on the
table.
_______________________
Michael B. Johnson<!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: adding records into a database using vb 
Back to top
Login to vote
Steve Gerrard1

External


Since: Aug 04, 2004
Posts: 9



(Msg. 3) Posted: Tue Feb 08, 2005 6:58 pm
Post subject: Re: adding records into a database using vb [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Devin Panchal" <d.panchal DeleteThis @ntlworld.com> wrote in message
news:vg6Od.591$1Y.585@newsfe4-gui.ntli.net...
| hi,
|
| Dim Assignment2 As Connection
| Dim rs As Recordset
|
| Private Sub cmdAddRecord_Click()
| Dim i As Integer
| Set db1 = New ADODB.Connection
| db1.Provider = "Microsoft.Jet.OLEDB.4.0;"
| db1.ConnectionString = "..."
| db1.Open
| Dim ar As ADODB.Recordset
| Set ar = New ADODB.Recordset
|
| ar.Open "select * from submission_info", Assignment2, adOpenDynmic,
| adLockOptimistic
|
|
| but when i run the code and click on add, i get an error sayding 'the
| connection cannot be used to perform this operation. it is either
closed or
| invalid in this context'.
|

You have specified Assignment2 as the connection object for your
recordset, but you have opened the db1 connection object. Either open
the Assignment2 connection, or pass db1 as the connection for your
recordset.
 >> Stay informed about: adding records into a database using vb 
Back to top
Login to vote
user3614

External


Since: Jan 31, 2005
Posts: 30



(Msg. 4) Posted: Wed Feb 09, 2005 12:40 pm
Post subject: Re: adding records into a database using vb [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

thanx for the help, my bad.
i got it working now.

thanx

devin

"Steve Gerrard" <mynamehere DeleteThis @comcast.net> wrote in message
news:sqidnWgc3IOk85TfRVn-2w@comcast.com...
 >
 > "Devin Panchal" <d.panchal DeleteThis @ntlworld.com> wrote in message
 > news:vg6Od.591$1Y.585@newsfe4-gui.ntli.net...
 > | hi,
 > |
 > | Dim Assignment2 As Connection
 > | Dim rs As Recordset
 > |
 > | Private Sub cmdAddRecord_Click()
 > | Dim i As Integer
 > | Set db1 = New ADODB.Connection
 > | db1.Provider = "Microsoft.Jet.OLEDB.4.0;"
 > | db1.ConnectionString = "..."
 > | db1.Open
 > | Dim ar As ADODB.Recordset
 > | Set ar = New ADODB.Recordset
 > |
 > | ar.Open "select * from submission_info", Assignment2, adOpenDynmic,
 > | adLockOptimistic
 > |
 > |
 > | but when i run the code and click on add, i get an error sayding 'the
 > | connection cannot be used to perform this operation. it is either
 > closed or
 > | invalid in this context'.
 > |
 >
 > You have specified Assignment2 as the connection object for your
 > recordset, but you have opened the db1 connection object. Either open
 > the Assignment2 connection, or pass db1 as the connection for your
 > recordset.
 >
 ><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: adding records into a database using vb 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> Visual Basic All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]