Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jhermiz
3564 Posts |
Posted - 2004-01-20 : 09:13:11
|
Wanted to try asp out for some testing...and ive always used VB.So I tried this for an asp page:<% '---Dim the variablesDim ConnDim rsSet Conn = Server.CreateObject("ADODB.Connection")Set rs = Server.CreateObject("ADODB.Recordset")Conn.Open "Driver={SQL Server};" & _"Server=HERCULES;" & _"Database=SPI;" & _"UID=me;" & _"PWD=pwd;"Set rs = Conn.Execute("SELECT * FROM Logins")If(rs.eof) Then Response.write("No Records Found")End Ifdo until rs.eof Response.write(rs("Name")) rs.movenextlooprs.CloseConn.CloseSet rs = nothingSet Conn = nothing %> And then I named the file "test.html" and I also tried "test.asp"with test.asp if i open it or throw it in the browser it just shows my code. With the other file it shows nothing.Am I connecting correctly? I have the IIS package installed on my PC, and our web server here at work supports ASP. So what am I doing wrong?Thanks,Jon |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-01-20 : 09:26:10
|
you can't just browse to an ASP file, the IIS service has to process it. It must be saved somewhere you can get to from the web server. then, instead of opening up "c:\inetput\wwwroot\test.asp" in your browser, you open up "\\computername\test.asp" or whatever the actual URL would be on the web server. Then, it will get processed by the server.- Jeff |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2004-01-20 : 09:28:36
|
have you got the IIS settings set up to execute your scripts?You could try putting <% @language = "vbscript" %> at the top, but it should work without that.-------Moo. :) |
|
|
jhermiz
3564 Posts |
Posted - 2004-01-20 : 10:24:19
|
Duhh...I knew that :-dThanks guys,Jon |
|
|
jhermiz
3564 Posts |
Posted - 2004-01-20 : 10:35:23
|
Dope some more questions...1) Can I do sometihng like this:<%@ language=vbscript%> <html><body><table width=100><% '---Dim the variablesDim ConnDim rsSet Conn = Server.CreateObject("ADODB.Connection")Set rs = Server.CreateObject("ADODB.Recordset")Conn.Open "Driver={SQL Server};" & _"Server=HERCULES;" & _"Database=SPI;" & _"UID=myID;" & _"PWD=myPwd;"Set rs = Conn.Execute("SELECT * FROM Logins")If(rs.eof) Then Response.write("No Records Found")End Ifdo until rs.eof <tr><td> Response.write(rs("Name")) </tr></td> rs.movenextlooprs.CloseConn.CloseSet rs = nothingSet Conn = nothing %></table></body></html> I want to basically create a row and one column to hold the name.Finally my second question is...I forgotten the little html that I knew...but lets say I wanted to create a page with one text box..."feedback" and a button "submit" so that someone enters feedback and clicks submit and it inserts it into a feedback table.Anyone have sample code for this...I always learn by example Thanks again,Jon |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2004-01-20 : 11:07:33
|
for your first question, you have the closing tags in the wrong order -- close out the TD before you close out the TR.to print a nice table of an entire recordset, you can do something like this:<table><%do while not r.eof%> <tr> <%for each f in r.field%> <td><%=r(f).value%></TD> <%next%> </Tr><%r.movenextloop%></table>you can loop through and print the headers from the fields() collection before printing the data as well if you like.- Jeff |
|
|
jhermiz
3564 Posts |
Posted - 2004-01-20 : 11:12:57
|
im guessing you cant put html inside of asp:<%@ language=vbscript%> <html><body><table width=100><% '---Dim the variablesDim ConnDim rsSet Conn = Server.CreateObject("ADODB.Connection")Set rs = Server.CreateObject("ADODB.Recordset")Conn.Open "Driver={SQL Server};" & _"Server=HERCULES;" & _"Database=SPI;" & _"UID=sa;" & _"PWD=sequoia;"Set rs = Conn.Execute("SELECT * FROM Logins")If(rs.eof) Then Response.write("No Records Found")End Ifdo until rs.eof <tr> <td> Response.write(rs("Name")) </td> </tr> rs.movenextlooprs.CloseConn.CloseSet rs = nothingSet Conn = nothing %></table></body></HTML> The page cannot be displayed with this...Jon |
|
|
jhermiz
3564 Posts |
Posted - 2004-01-20 : 11:15:46
|
ok yes this part works...<%@ language=vbscript%> <html><body><table width=100><% '---Dim the variablesDim ConnDim rsSet Conn = Server.CreateObject("ADODB.Connection")Set rs = Server.CreateObject("ADODB.Recordset")Conn.Open "Driver={SQL Server};" & _"Server=HERCULES;" & _"Database=SPI;" & _"UID=sa;" & _"PWD=sequoia;"Set rs = Conn.Execute("SELECT * FROM Logins")If(rs.eof) Then Response.write("No Records Found")End Ifdo until rs.eof%> <tr> <td> <% Response.write(rs("Name")) %></td> </tr> <% rs.movenextlooprs.CloseConn.CloseSet rs = nothingSet Conn = nothing %></table></body></HTML> What about my second problem. I just want a button to INSERT into for feedback...Jon |
|
|
jhermiz
3564 Posts |
Posted - 2004-01-20 : 11:27:56
|
You did also mention I can print the names of the columns.How would I do that with the following code:<%@ language=vbscript%> <html><body><table width=100><% '---Dim the variablesDim ConnDim rsSet Conn = Server.CreateObject("ADODB.Connection")Set rs = Server.CreateObject("ADODB.Recordset")Conn.Open "Driver={SQL Server};" & _"Server=HERCULES;" & _"Database=SPI;" & _"UID=sa;" & _"PWD=sequoia;"Set rs = Conn.Execute("SELECT * FROM Logins")If(rs.eof) Then Response.write("No Records Found")End Ifdo until rs.eof%> <tr> <td> <% Response.write(rs("Name")) %></td> </tr> <% rs.movenextlooprs.CloseConn.CloseSet rs = nothingSet Conn = nothing %></table></body></html> Thanks,Jon |
|
|
|
|
|
|
|