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!

How do i add data to the grid control ?

Status
Not open for further replies.

kgaustria

Programmer
May 23, 2001
5
PK
Can anyone give some details on how to add data to the grid control ? Here's the module im working on ....

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

'strConn = &quot;PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=.\pcinvsys\sample.mdb;&quot;
'strConn = strConn & server.mappath(&quot;..\ken\pcinvsys\sample.mdb&quot;) & &quot;;&quot;

Conn.Open &quot;PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=.\sample.mdb;&quot;
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>
<center>
<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;Button&quot; title=&quot;Add to the table &quot; value=&quot;ADD&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;Button&quot; title=&quot;Edit the selected record&quot; value=&quot;EDIT&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;Button&quot; title=&quot;Delete the record(s)&quot; value=&quot;DELETE&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;Button&quot; title=&quot;Updates the table&quot; value=&quot;UPDATE&quot; width=&quot;40&quot; height=&quot;40&quot;>
</center>
</form>
</body>
</html>

Thanks in advance....
 
hi
First Create RDS.DataControl then bound Grid Control or any other Data aware Contol with ur datacontrol
here is a sample code:

<html>
<body>
<OBJECT classid=clsid:BD96C556-65A3-11D0-983A-00C04FC29E33 height=1 id=datacontrol
width=1>
</OBJECT>

<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; datasrc=&quot;#datacontrol&quot; >
</OBJECT>

</body>
</html>


<script language=vbs>
sub window_onload
datacontrol.connect = &quot;your connection string&quot;
datacontrol.sql = &quot;select * from table&quot;
datacontrol.server = &quot;server&quot;
datacontrol.refresh
grid.refresh
end sub
</script>

see how your grid is bounded to datacontrol using datasrc=&quot;#datacontrol&quot;









 
im still having errors like object doesnt support this property or method... &quot;datacontrol.connect&quot;

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

Conn.Open &quot;PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=.\sample.mdb;&quot;
Set RS = createobject(&quot;ADODB.Recordset&quot;)
RS.activeconnection=Conn
rs.Cursortype=2 'adOpenDynamic
sqlStatement = &quot;Select * from PCINV&quot;
RS.open sqlStatement

datacontrol.connect = &quot;PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=.\sample.mdb;&quot;
datacontrol.sql = &quot;select * from PCINV&quot;
datacontrol.refresh
dbgrid.refresh

'data1.databasename = &quot;.\sample.mdb&quot;
'do while not rs.eof
' if isnull(rs(&quot;users&quot;)) then
' exit do
' else
' myfield=rs(&quot;users&quot;)
' DBGRID.ROWS=MYFIELD
' rs.movenext
' end if
'loop

end sub
-->
</script>
</head>
<body>
<OBJECT ID=&quot;datacontrol&quot; WIDTH=&quot;10%&quot; HEIGHT=&quot;5%&quot; CLASSID=&quot;CLSID:67397AA3-7FB1-11D0-B148-00A0C922E820&quot;>
</OBJECT>
<OBJECT ID=&quot;DBGrid&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; datasrc=&quot;#datacontrol&quot;>
</OBJECT>

<HR>
<form>
<center>
<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;Button&quot; title=&quot;Add to the table &quot; value=&quot;ADD&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;Button&quot; title=&quot;Edit the selected record&quot; value=&quot;EDIT&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;Button&quot; title=&quot;Delete the record(s)&quot; value=&quot;DELETE&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;Button&quot; title=&quot;Updates the table&quot; value=&quot;UPDATE&quot; width=&quot;40&quot; height=&quot;40&quot;>
</center>
</form>
</body>
</html>
 
U dont have to use ADODB.Recordset here
if u have ADO 2.1 Rds or ADO 2.5 just run code writen above and u'll see ur data on grid
reason u got that error is that u dont have RDS in ur system
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top