Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database connection 2

Status
Not open for further replies.

kgaustria

Programmer
May 23, 2001
5
PK
How can i connect an access database in VBScript ? And how can i get those data in a grid control ? can you give some examples ?
 
That's a very demanding task for VBScript.
Just what are you trying to achieve.
Might be easier to write the data access in a VB DLL and call it from VBScript.

Anyway, to access a MDB from a datagrid:

First, I would use either the reference or object tags so that VBScript would recognize the data grid and the ADO Recordset library.

Second, within the reference and object tags I would set the properties of the data grid including what database it is to be connected to.

Third, I'd write the SQL statements to access the database.

Good luck

 
Thanks jerjim but can you be more broader with that ? Here a sample of my code as soon as i click the browse button an error occurs "Object Required : server"

<html>
<head>
<title>PC Inventory System</title>
<script language=&quot;VBScript&quot; RUNAT=&quot;server&quot;>
<!--
sub cmdbrowse_onclick
msgbox &quot;hello&quot;
dim Conn, RS, strConn, sqlStatement
Set Conn = server.createobject(&quot;ADODB.Connection&quot;)

strConn = &quot;PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=&quot;
strConn = strConn & server.mappath(&quot;..\ken\pcinvsys\sample.mdb&quot;) & &quot;;&quot;
Conn.Open
Set RS = createobject(&quot;ADODB.Recordset&quot;)
RS.activeconnection=Conn
rs.Cursortype=2 'adOpenDynamic
sqlStatement = &quot;Select * from PCINV Where Users=&quot;&quot;E. LOPEZ&quot;&quot;&quot;
RS.open sqlStatement
end sub
-->
</script>
</head>
<body>
<!--<OBJECT ID=&quot;DBGrid Control&quot; WIDTH=&quot;100%&quot; HEIGHT=&quot;100%&quot; align=&quot;middle&quot; NAME=&quot;grid&quot; CLASSID=&quot;CLSID:00028C00-0000-0000-0000-000000000046&quot;>
</OBJECT> -->
<HR>
<!--<form method=&quot;POST&quot; action=&quot;view.asp&quot;>
<p><input type=&quot;submit&quot; value=&quot;View&quot; name=&quot;View&quot;></p>
</form> -->
<form>
<center>
<!--<input name=&quot;cmdbrowse&quot; type=&quot;Image&quot; title=&quot;View the contents&quot; src=&quot;./img/icons/table.ico&quot; width=&quot;40&quot; height=&quot;40&quot;> -->
<input name=&quot;cmdbrowse&quot; type=&quot;Button&quot; title=&quot;View the contents&quot; Value=&quot;BROWSE&quot; width=&quot;40&quot; height=&quot;40&quot;>

&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<input name=&quot;cmdadd&quot; type=&quot;Image&quot; title=&quot;Add to the table &quot; src=&quot;./img/icons/folder04.ico&quot; width=&quot;40&quot; height=&quot;40&quot;>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<input name=&quot;cmdedit&quot; type=&quot;image&quot; title=&quot;Edit the selected record&quot; src=&quot;./img/icons/pencil01.ico&quot; width=&quot;40&quot; height=&quot;40&quot;>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<input name=&quot;cmddelete&quot; type=&quot;Image&quot; title=&quot;Delete the record(s)&quot; src=&quot;./img/icons/delete.bmp&quot; width=&quot;40&quot; height=&quot;40&quot;>
&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
<input name=&quot;cmdupdate&quot; type=&quot;Image&quot; title=&quot;Updates the table&quot; src=&quot;./img/icons/save.bmp&quot; width=&quot;40&quot; height=&quot;40&quot;>
</center>
</form>
</body>
</html>


Thanks in advance... :)
 
I use this code to test ODBC connections.

<html>
<head>
<title>
Connection Test
</title></head>

<body>
<%
dim myConn
set myConn = server.createobject(&quot;ADODB.Connection&quot;)

myConn.Open ODBCtest

If myConn.state = 1 then
response.write(&quot;Connection opened successfully<p>&quot;)
else
response.write(&quot;Error. Connection could not be opened.<P>&quot;)
end if

myconn.close
set myConn = Nothing

%>

</body>

</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top