-
July 22nd, 2009, 08:23 AM
#1
adodb connection
i have created textboxes for each fields available in an existing database file in a vb form.i need to show the data in the textboxes whenever i click the command buttons next and previous.help needed
-
July 22nd, 2009, 09:07 AM
#2
Re: adodb connection
Why don't you use DBTextBOX?
-
July 22nd, 2009, 09:17 AM
#3
Re: adodb connection
this is my code
Private Sub Form_Load()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "datasource=E:\project1\databmdb;"
cn.Open//shows error here
str = "Select * from table"
rs.Open str, cn
Set Text1.DataSource = rs
Text1.DataField = "NAME"
end sub
-
July 22nd, 2009, 10:23 AM
#4
Re: adodb connection
In your Open method you need
cn.open (ConnectionString, optional username, optional password, optional options)
So try this
Dim cn as ADODB.Connection
Dim rs as ADODB.Recordset
dim strCN as string
Set cn = new adodb.connection
set rs = new adodb.recordset
strCN = "Provider=Microsoft.Jet.OLEDB.4.0;" & "datasource=E:\project1\databmdb;"
cn.open strCN
rs.open "Select * from table", cn, adOpenStatic, adLockReadOnly (or whatever lock method you want)
Last edited by arkansascontrols; July 22nd, 2009 at 10:26 AM.
-
July 22nd, 2009, 10:43 AM
#5
Re: adodb connection
Personally I prefer not to bind the text boxes to a datasource. Typically I will use an array of text boxes and populate them in a loop
for example if there are 10 fields in the RS and an array of 10 textboxes to be populated the code may look somethign like.
Code:
For x=0 to 9
TextBox1(x).text=RS(x)
Next
Using this method the text box is not bound to the database so any changes to the data in the boxes do not have any effect on the database unless you write code to do so in your save routine. Basically the opposite of what is above
Code:
For x =0 to 9
RS(x)=TextBox1(x).text
Next
-
July 22nd, 2009, 10:49 AM
#6
Re: adodb connection
I agree with DataMiser I don't like Data Controls or databound controls.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|