May 24, 2018, 02:10:24 AM

Author Topic: Need help connecting database to form controls  (Read 8538 times)

0 Members and 1 Guest are viewing this topic.

geoinscho

  • Guest
Need help connecting database to form controls
« on: March 04, 2005, 04:02:03 PM »
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
« Last Edit: March 07, 2005, 10:40:39 AM by geoinscho »

Offline Cobra

  • cool?
  • Administrator
  • Seasoned Poster
  • *****
  • Posts: 447
  • Country:
  • Gender: Male
  • My mom says im cool!
Re:Need help connecting database to form controls
« Reply #1 on: March 06, 2005, 05:47:19 PM »
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.

geoinscho

  • Guest
Re:Need help connecting database to form controls
« Reply #2 on: March 14, 2005, 08:43:25 AM »
I am using Access 2000 on a Windows 98 Dell Computer.  I'm not sure what other information to look for.

Offline Cobra

  • cool?
  • Administrator
  • Seasoned Poster
  • *****
  • Posts: 447
  • Country:
  • Gender: Male
  • My mom says im cool!
Re:Need help connecting database to form controls
« Reply #3 on: March 14, 2005, 12:12:37 PM »
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.

geoinscho

  • Guest
Re:Need help connecting database to form controls
« Reply #4 on: March 16, 2005, 08:08:43 AM »
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?

Offline Cobra

  • cool?
  • Administrator
  • Seasoned Poster
  • *****
  • Posts: 447
  • Country:
  • Gender: Male
  • My mom says im cool!
Re:Need help connecting database to form controls
« Reply #5 on: March 16, 2005, 09:21:49 AM »
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.

geoinscho

  • Guest
Re:Need help connecting database to form controls
« Reply #6 on: April 01, 2005, 05:07:04 PM »
Okay, but I'm still not clear on where to put it.
We never worked with ASP files or root files.

Offline Cobra

  • cool?
  • Administrator
  • Seasoned Poster
  • *****
  • Posts: 447
  • Country:
  • Gender: Male
  • My mom says im cool!
Re:Need help connecting database to form controls
« Reply #7 on: April 04, 2005, 12:53:16 PM »
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.

geoinscho

  • Guest
Re:Need help connecting database to form controls
« Reply #8 on: April 06, 2005, 10:49:12 AM »
It's for a local windows-based application.