 |
|
 |
|
Next: Locale
|
| Author |
Message |
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 |
|
 |  |
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"
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 >> Stay informed about: adding records into a database using vb |
|
| Back to top |
|
 |  |
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" wrote in message
| 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 |
|
 |  |
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" wrote in message
>
> | 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 |
|
 |  |
| Related Topics: | SQL and VB- how do u count records - hi, i've got a table in a access file, and i want to display a number on a form, displaying a total unmber of a record. e.g. i have a table with paper submissions, and i want to display the total number of submissions. and i want to do it as a click..
Filtering records using textbox on form - Can I use the value of a bound textbox on an open form, as a criteria in a query. If so what would be the correct code for the SQL. If not how can I hold the required value (number) that is selected by the user from a combo box at startup, so that I can....
I need help with some VB or SQL programming for a database. - I need some VB or SQL coding to finish up an access database program. I am trying to choose selected records from an access table based on certain criteria. Example: 2 records needed out of 4 total records and the code should choose the 2 records with...
Shared Database Connection? - I want to use an oracle odbc connection on my windows server for an application I am writing for client workstations. The result is I don't want to install the oracle client to get sql*net on every workstation i am running my the program on. What shoul...
Package & Deployment wizard: Update a database - Dear, I have developed a standalone VB6.0 application which uses an access database. I deployed this application with the "Package & Deployment"-wizard from Visual Basic, and it works fine. Due to some new requirements I had to add an ext... |
|
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
|
|
|
|
 |
|
|