Need help connecting database to form controls

Started by geoinscho, March 04, 2005, 04:02:03 PM

Previous topic - Next topic
March 04, 2005, 04:02:03 PM Last Edit: March 07, 2005, 10:40:39 AM by geoinscho
I'm using Visual Basic 6.0 at work (AAARGH!).  If I were using 7.0, this would be no problem.  But with 6.0 I can connect to the database...I even get a confirmation of connection after clicking on the "Test Connection" button.  

But I cannot get any of the controls on the form to pick up any data from the database.  When I click on the text box's DataSource attribute, it only gives me DataConnection1 as an option, but I can find NO other reference to DataConnection1 in the project.

And HELP doesn't work, because I get an error message that says that the MSDN collection is not available and must be reinstalled.  But I have no idea who has the MSDN software in order to reinstall it.

At first I thought MSDN meant (M)icro(S)oft (D)umb@$$ (N)etwork....but now I know it for sure.
________________________________________

It is a MicroSoft Access 2000 Database.
Thanks,
Geo

Can ya give me more info..

What is the database, is it a Windows APP or is it a Web APP..

etc.. etc..

I am not suffering with insanity... I am loving every minute of it.

I am using Access 2000 on a Windows 98 Dell Computer.  I'm not sure what other information to look for.

To access info from an Access database you should have something like

<%
dim cmd, conn, rs, strSQL
set conn=server.CreateObject("ADODB.Connection")
set rs=server.CreateObject("ADODB.Recordset")
set cmd=server.CreateObject("ADODB.Command")
filepath=Server.MapPath("database_path/here/database_name.mdb")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filepath

strSQL = "SELECT * TOP 1 FROM database_name"
rs.open strSQL, conn, 1, 1

%>
<form>
<input type="text" name="field_name" value="<%=rs("database_field")%>
</form>


--------------------------------------------------------

That example will connect to your database and pull whatever data is in "database_field" and place it as the default value in your form field.

if you want to read from that form then just use

request.form("field_name")

That what yer lookin for?
I am not suffering with insanity... I am loving every minute of it.

Sort of, except that I don't know where to add this block of code.  In school, it was as drag-and-drop; so, I think the course left me rather crippled when it comes to older versions of visual basic.  (Come to think of it, I probably used Visual Studio .NET.)

Could you please tell me where I would place the code?

Sure man,
Normally i put my connection strings in an include file below the root level, but for this example we can leave it in the main file.

---------- dbconn.asp ----------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<body>
<%
dim cmd, conn, rs, strSQL
set conn=server.CreateObject("ADODB.Connection")
set rs=server.CreateObject("ADODB.Recordset")
set cmd=server.CreateObject("ADODB.Command")
filepath=Server.MapPath("database_path/here/database_name.mdb")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filepath

strSQL = "SELECT * TOP 1 FROM database_name"
rs.open strSQL, conn, 1, 1

%>
<form>
<input type="text" name="field_name" value="<%=rs("database_field")%>
</form>

<%
rs.close
set strSQL = Nothing
%>
</body>
</html>
-------------------------------------------

Now just save that file with a ASP extension and it will connect to your database fine and display the top record from the database into your form.
I am not suffering with insanity... I am loving every minute of it.

Okay, but I'm still not clear on where to put it.
We never worked with ASP files or root files.

Is this getting used on a website?

or are you writing a local application?

Because what i have given is for a website.
I am not suffering with insanity... I am loving every minute of it.


SMF spam blocked by CleanTalk