ASP connecting to SQL Server database - sql

<%
'declare the variables
Dim Recordset
Dim sql
dim Conn
Dim name1,email1,phone1,company1,title1
name1 = request.form("TxtName")
email1 = request.form("TxtEmail")
phone1 = request.form("TxtPhone")
company1 = request.form("TxtCompany")
title1 = request.form("TxtJob")
'create an instance of the ADO connection and recordset objects
Set Conn= Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
'open the connection to the database
Conn.ConnectionString = "DSN=blah;User Id=...;Password=...;Database=...."
'Open the recordset object executing the SQL statement and return records
Recordset.Open
Conn.open
sql="INSERT INTO register (Name, email, phonenumber, company, title)"
sql=sql & "values ('"& name1 &"','"& email1 &"','"& phone1 &"','"& company1 &"','"& title1 &"')"
Conn.Execute(sql)
Conn.Close()
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample Registration Page</title>
</head>
<body>
<form name"form" action="">
<table>
<tr>
<td>Full Name:</td>
<td>
<input name="TxtName" id="TxtName" type="text" />
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<input name="TxtEmail" id="TxtEmail" type="text" />
</td>
</tr>
<tr>
<td>Phone:</td>
<td>
<input name="TxtPhone" id="TxTPhone" type="text" />
</td>
</tr>
<tr>
<td>Company:</td>
<td>
<input name="TxtCompany" id="TxtCompany" type="text" />
</td>
</tr>
<tr>
<td>Job Title:</td>
<td>
<input name="TxtJob" id="TxtJob" type="text" />
</td>
</table>
<input name="button" ID="Button1" value="submit" type="Submit" />
</form>
</body>
</html>
I get an error 500 message when I run this page, I have no idea where my mistake is.
I also did make the DSN connection with name called blah to my SQL Server.
I ran the ASP part alone and it works, however the database section is where my problem lies. I really appreciate any help since I'm relatively new to this.

First, you should activate the friendly display of errors on your web server in order to know exactly what and where the error is instead of the generic, say nothing Error 500 that you are getting at this moment.
Second, in the meantime, add a couple of Response.write followed by Response.Flush to see what's going and where; for example to display the result of the building of the sql string:
sql = ...
response.write sql & "<br>"
response.flush
Second, you try to open a Recordset with no associated Command object or sql query string; you cannot do that and in fact, you don't need any Recordset here because your have an Insert query, not a Select query.
Finally, using a DSN with ADODB is a bad idea. DSN are for ODBC and by using ODBC under ADODB, you are adding an old, useless layer to your data connection. You should instead use the latest native OLEDB provider for your SQL-Server. Search the web for Connection String and you will get a few web sites with full details on the available providers along with their connection strings.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Sample Registration Page</title>
</head>
<body>
<form action="registration.asp" method="POST" name="form1">
<table>
<tr>
<td>Full Name:</td>
<td><input name="TxtName" id="TxtName" type="text" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input name="TxtEmail" id="TxtEmail" type="text" /></td>
</tr>
<tr>
<td>Phone:</td>
<td><input name="TxtPhone" id="TxTPhone" type="text" /></td>
</tr>
<tr>
<td>Company:</td>
<td><input name="TxtCompany" id="TxtCompany" type="text" /></td>
</tr>
<tr><td>Job Title:</td>
<td><input name="TxtJob" id="TxtJob" type="text" /></td>
</table>
<input name="button" ID="Button1" value="submit" type="Submit" />
</form>
</body>
</html>
<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" then
Dim Conn, Rs, ConnString, SQL_Insert
Dim name1,email1,phone1,company1,title1
name1 = request.form("TxtName")
email1 = request.form("TxtEmail")
phone1 = request.form("TxtPhone")
company1 = request.form("TxtCompany")
title1 = request.form("TxtJob")
Set Conn= Server.CreateObject("ADODB.Connection")
ConnString = "DSN=blah;User Id=...;Password=...;Database=...."
Conn.Open ConnString
SQL_Insert="INSERT INTO register (Name, email, phonenumber, company, title)" & _
"values ('"& name1 &"','"& email1 &"','"& phone1 &"','"& company1 &"','"& title1 &"');"
Conn.Execute SQL_Insert
Conn.Close
Set Conn = Nothing
Set SQL_Insert = Nothing
End If
%>
As you are not retrieving any data from database there is no need of RecordSet.
copy and paste this code in a file & name it "registration.asp"
Don't forget to replace the connection string with the actual one
for tutotrial visit www.w3schools.com
hope this is helpful

A space char seems to be missing on the SQL.
sql = "INSERT INTO register (...)SPACE-MISSING-HERE"
sql = sql & "values (...)"
Conn.Execute(sql)
Conn.Close()

Related

Posting to Servlet From Two Forms Within HTML Page

Solution: Just added null default values to the HTML parameters. Seems to have solved it!
So I have an admin page (HTML) with two forms. First form is to add to an SQL database and has 4 input boxes, second form deletes from a SQL database and has 1 input box. If I use the first form, everything is OK. But if I leave the first form empty and just put a value for the 2nd form, I get an NumberFormatException for String = "" I can only assume because the first form is empty. I'm trying to have the user either fill the first form and leave the 2nd empty, or vice versa. Any advice on how to better approach this would be great.
This is my HTML page
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Admin</title>
<link rel="stylesheet" href="myStyle.css">
</head>
<body>
<h1>Welcome to the admin page.</h1>
<h2>Please enter the new product to be added:</h2>
<form action="eShop" method="Post">
<table class="tableBox">
<tr>
<td align="left"><b>Item Code:</b></td>
<td align="left"><input type="number" name="code"></td>
</tr>
<tr>
<td align="left"><b>Item Name:</b></td>
<td align="left"><input type="text" name="name"></td>
</tr>
<tr>
<td align="left"><b>Item Price:</b></td>
<td align="left"><input type="number" name="price"></td>
</tr>
<tr>
<td align="left"><b>Is Taxable:</b></td>
<td align="left"><input type="text" name="taxable"></td>
<tr>
<td align="center" colspan="2"><input type="submit" name="action" value="Update!"></td>
</tr>
</table>
</form>
<h2>Enter the code of the product you want to delete:</h2>
<form action="eShop" method="Post">
<table class="tableBox">
<tr>
<td align="left"><b>Item Code:</b></td>
<td align="left"><input type="number" name="code"></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="action" value="Delete!"></td>
</tr>
</table>
</form>
</body>
</html>
This is the section in my servlet that gets the parameters
else if(request.getParameter("action").equals("Delete!")) {
DataAccessImpl temp = new DataAccessImpl();
int code = Integer.parseInt(request.getParameter("code"));
temp.deleteItem(code);
}
This is the DataAccessImpl class used in the servlet, particularly the method that will delete the row.
public void deleteItem(int code) {
connect();
String deleteStm = ("DELETE FROM ProductCatalogue WHERE code = " + code);
PreparedStatement pstm = null;
System.out.println("Beginning to delete product from database...");
try {
pstm = conn.prepareStatement(deleteStm);
System.out.println("Delete complete!");
}
catch(SQLException e) {
e.printStackTrace();
}
}
in first form name your submit button like this:
<input type="submit" name="updateAction" value="Update!">
in second form name your submit button like this:
<input type="submit" name="deleteAction" value="Delete!">
Servlet Code should be like this:
else if(request.getParameter("deleteAction").equals("Delete!")) {
DataAccessImpl temp = new DataAccessImpl();
int code = Integer.parseInt(request.getParameter("code"));
temp.deleteItem(code);
}

In MVC, when I post the form, the model data is not posted, I can see the input fields properly named using inspect element. Looking for suggestions

In MVC, when I post the form, the model data is not posted, I can see the input fields properly named using inspect element. Please help me out....
Following is my code
Using (Html.BeginForm("_saveActivities", "Projects", FormMethod.Post, New With {.name = "frmActivity", .id = "frmActivity", .enctype = "multipart/form-data"}))
#Html.HiddenFor(Function(X) X.Project.ID)
#<table class="formTable">
<thead>
<tr>
<td colspan="2">Project Activties</td>
</tr>
</thead>
<tr>
<td colspan="2" style=" text-align:right; background-color:#DFDFDF">
To add new row click
click here
</td>
</tr>
<tr>
<td colspan="2" style=" background-color:#DFDFDF">
<table id="tblProjectActivities" style=" width:100%">
<tr>
<td style="width:1px;"></td>
<td style=" width:300px;" >Activity</td>
<td style=" width:110px;" >Start Date</td>
<td style=" width:110px;" >End Date</td>
<td style=" width:15px;"></td>
</tr>
#For Each Item In Model.ProjectActivities
Html.RenderPartial("_ProjectFormActivitiesRow", Item)
Next
</table>
</td>
</tr>
<tfoot>
<tr>
<td colspan="2">
<div id="buttonsActivityDiv" style=" position:relative; background-color:inherit; height:40px;">
<input type="submit" id="comActivity" value="Update Activities" class="k-button"/>
</div>
</td>
</tr>
</tfoot>
</table>
End Using
In parialview I have following code
#ModelType Models.ProjectActivityItem
#code
Dim strID As String = Guid.NewGuid.ToString
Dim strRowID As String = Guid.NewGuid.ToString
Dim strStateID As String = Guid.NewGuid.ToString("N")
End Code
<tr id="#strRowID">
<td>
<input type="hidden" name="ProjectActivties.Index" value="#strID" />
<input type="hidden" name="ProjectActivties[#(strID)].DetailEntity.ID" value="#Model.DetailEntity.ID"/>
<input type="hidden" name="ProjectActivties[#(strID)].DetailEntity.CreatedOn" value="#Model.DetailEntity.CreatedOn"/>
<input type="hidden" name="ProjectActivties[#(strID)].DetailEntity.CreatedBy" value="#Model.DetailEntity.CreatedBy"/>
<input type="hidden" name="ProjectActivties[#(strID)].DetailEntity.VersionEncoded" value="#Model.DetailEntity.VersionEncoded"/>
<input type="hidden" name="ProjectActivties[#(strID)].DetailEntity.ProjectID" value="#Model.DetailEntity.ProjectID"/>
<input type="hidden" id="#strStateID" name="ProjectActivties[#(strID)].DetailEntity.EntityState" value="#Model.DetailEntity.EntityState"/>
</td>
<td>#Html.TextBox("ProjectActivties[" & strID & "].DetailEntity.ActivityDescription", Model.DetailEntity.ActivityDescription, New With {.class = "inputAreaFull k-textbox"})</td>
<td>#Html.Kendo.DatePicker().Name("ProjectActivties[" & strID & "].DetailEntity.StartDate").Min(New DateTime(2000, 1, 1)).Value(Model.DetailEntity.StartDate).Format("dd-MMM-yyyy").HtmlAttributes(New With {.style = "width:110px"})</td>
<td>#Html.Kendo.DatePicker().Name("ProjectActivties[" & strID & "].DetailEntity.EndDate").Min(New DateTime(2000, 1, 1)).Value(Model.DetailEntity.EndDate).Format("dd-MMM-yyyy").HtmlAttributes(New With {.style = "width:110px"})</td>
<td>
<img src="#Url.Content("/Content/delete_icon.png")" onclick="removeProjectActivity('#strRowID','#strStateID')" style ="cursor:pointer" title="Delete Detail"/>
</td>
</tr>
and in controller, I am using
<HttpPost()> _
Function _saveActivities(lModel As Models.ProjectModel) As ActionResult
End Function
Following is my model.
Public Class ProjectActivity
Public Property ID As Int64
Public Property ProjectID As Int32
Public Property ActivityDescription As String
Public Property StartDate As DateTime
Public Property EndDate As DateTime
Public Property CreatedOn As DateTime
Public Property CreatedBy As Int32
Public Property ModifiedOn As DateTime
Public Property ModifiedBy As Int32
<NotMapped()> _
Public Property VersionEncoded As String
<NotMapped()> _
Public Property EntityState As EntityStateEnum
End Class
Public Class ProjectActivityItem
Inherits BaseObject
Public Property DetailEntity As Database.ProjectActivity
End Class
The model does not map with control's Id . It mapped With name. check your rendered control name & model property are same of different .

Error with Dreamweaver User Authentication when using levels

I am using Dreamweavers User Authentication, and since I have introduced the use of 'levels' it just keeps erroring
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Sybase][ODBC Driver][Adaptive Server Anywhere]Syntax error near 'group' on line 1
/coding/login.asp, line 29
My code is as follows
<%#LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/Conn_PSCRM_Demo.asp" -->
<%
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername = CStr(Request.Form("usercode"))
If MM_valUsername <> "" Then
Dim MM_fldUserAuthorization
Dim MM_redirectLoginSuccess
Dim MM_redirectLoginFailed
Dim MM_loginSQL
Dim MM_rsUser
Dim MM_rsUser_cmd
MM_fldUserAuthorization = "group"
MM_redirectLoginSuccess = "quote-search.asp"
MM_redirectLoginFailed = "no_access.asp"
MM_loginSQL = "SELECT usercode, epros_password"
If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," & MM_fldUserAuthorization
MM_loginSQL = MM_loginSQL & " FROM DBA.[user] WHERE usercode = ? AND epros_password = ?"
Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command")
MM_rsUser_cmd.ActiveConnection = MM_Conn_PSCRM_Demo_STRING
MM_rsUser_cmd.CommandText = MM_loginSQL
MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200, 1, 255, MM_valUsername) ' adVarChar
MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200, 1, 255, Request.Form("password")) ' adVarChar
MM_rsUser_cmd.Prepared = true
Set MM_rsUser = MM_rsUser_cmd.Execute
If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
' username and password match - this is a valid user
Session("MM_Username") = MM_valUsername
If (MM_fldUserAuthorization <> "") Then
Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
Else
Session("MM_UserAuthorization") = ""
End If
if CStr(Request.QueryString("accessdenied")) <> "" And true Then
MM_redirectLoginSuccess = Request.QueryString("accessdenied")
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginSuccess)
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
End If
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div>
<h1>Coding</h1>
<p>Enter your username and password below to login</p>
<form ACTION="<%=MM_LoginAction%>" METHOD="POST" id="coding_login" name="coding-login">
<table width="50%" border="0" cellspacing="2" cellpadding="2">
<tr>
<th scope="row">Username:</th>
<td><label for="usercode"></label>
<input name="usercode" type="text" required id="usercode" size="5" maxlength="3"></td>
</tr>
<tr>
<th scope="row">Password:</th>
<td><label for="password"></label>
<input name="password" type="password" id="password" size="10" maxlength="25" required></td>
</tr>
<tr>
<th scope="row"> </th>
<td><input type="submit" name="Login" id="Login" value="Login"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
Any help would be greatly accepted.
"group" is a reserved word in sybase (and I imagine many other database systems)
on line 16 try
MM_fldUserAuthorization = """group"""

Difficulty Finding Table CheckBoxes

I'm trying to use Excel VBA to perform a very manual process in IE. I've worked with VBA and IE enough to do easy tasks like enter text into fields or interact with buttons, but I'm having a difficult time wrapping my head around this.
I have a list of fields in Excel: First Name, Last Name, Email Address. There are over two thousand rows of information in the spreadsheet. The website I'm working with has a list of over three thousand rows of information (same information with the addition of a checkbox), except it only loads a maximum of 100 rows at a time. Every row of data in Excel exists in the web tool.
I'd like to have my procedure iterate over the names and check the corresponding row on the webpage. The problem is figuring out how to identify the input id for the corresponding checkbox. I'm not very familiar with HTML so my code is very rudimentary... I've spent much of the day writing this:
Sub Test()
Dim str As String
Dim ie As SHDocVw.InternetExplorer
Dim doc As HTMLDocument
Dim tbls As Object
Dim tbl As Object
Dim trow As Object
Dim trs As Object
Dim Cell As Range
Set ie = New SHDocVw.InternetExplorer
ie.navigate "https://test.com"
ie.Visible = True
Set doc = ie.Document
Set tbls = doc.getElementsByTagName("TABLE")
For Each Cell In Range("A2:A2200")
For Each tbl In tbls
For Each trow In tbl.Rows
If InStr(1, trow.Cells(i).innerText, Cell.Offset(0, 1) & ", " & Cell) > 0 Then
Debug.Print trow.Cells(0).innerText
Stop
End If
Next trow
Next tbl
Next Cell
End Sub
The above code is able to identify the cell on the page that matches the cell in the workbook, but I can't figure out how to find the id to the associated checkbox. The site is private, so I can't provide a link. See below for what appears to be the relevant piece of source code for the site:
<div>
<table cellspacing="0" border="0" id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults" style="border-color:Black;border-width:1px;border-style:Solid;width:100%;border-collapse:collapse;">
<tr>
<td colspan="6">
<table id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_tabPager" border="0" cellpadding="5" width="100%">
<tr>
<td style="border-style:none;">
<a id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_lbPrev" disabled="disabled">Previous</a>
<a id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_lbNext" disabled="disabled">Next</a>
</td>
<td style="border-style:none;" align="right">
<b>Showing:</b>
<span id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow"><input id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_0" type="radio" name="ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow" value="10" checked="checked" /><label for="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_0">10 People</label><input id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_1" type="radio" name="ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow" value="25" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow$1\',\'\')', 0)" /><label for="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_1">25 People</label><input id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_2" type="radio" name="ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow" value="50" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow$2\',\'\')', 0)" /><label for="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_2">50 People</label><input id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_3" type="radio" name="ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow" value="100" onclick="javascript:setTimeout('__doPostBack(\'ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$rblShow$3\',\'\')', 0)" /><label for="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_rblShow_3">100 People</label></span>
</td>
</tr>
<tr id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl01_trSelectOptions">
<td colspan="2" style="border-style: none;" align="left">
Select All on Page
Clear All on Page
<a class="link_w_img" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$ctl09", "", true, "", "", false, true))">
<img src="/images/all.gif" />
<span>Select Entire List</span></a>
<a class="link_w_img" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl01$ctl11", "", true, "", "", false, true))">
<img src="/images/none.gif" />
<span>Clear Entire List</span></a>
</td>
</tr>
</table>
</td>
</tr>
<tr class="gridheader" align="left">
<th scope="col">Select</th>
<th scope="col">Last Name</th>
<th scope="col">First Name</th>
<th scope="col">Middle Name</th>
<th scope="col">E-mail Address</th>
<th scope="col" style="width:0px;"> </th>
</tr>
<tr class="griditem" align="center">
<td>
<input id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_SelectCheckBox" type="checkbox" name="ctl00$ctl00$all_content$all_content$content$ucUserSearch$gvSearchResults$ctl03$SelectCheckBox" />
</td>
<td align="left" onmouseover="ShowPopup('ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_divTip');" onmouseout="HidePopup();">Demo1</td>
<td align="left" onmouseover="ShowPopup('ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_divTip');" onmouseout="HidePopup();">Test</td>
<td align="left" onmouseover="ShowPopup('ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_divTip');" onmouseout="HidePopup();"> </td>
<td align="left" onmouseover="ShowPopup('ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_divTip');" onmouseout="HidePopup();">Demo1#Test.com</td>
<td style="width:0px;">
<div id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_divTip" class="popup">
<div class="popupbg">
<table>
<tr>
<td style="vertical-align:top;">
<span id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_lblName" style="font-weight:bold;">Demo1, Test </span>
<br />E-mail:<span id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_lblEmail">Demo1#Test.com</span><br />
<table cellspacing="0" border="0" id="ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_dgDemos" style="border-style:None;border-collapse:collapse;margin-top:-1.25em;">
<tr>
<td>
</td><td>
</td>
</tr><tr>
<td>
Employee ID:
</td><td>
N/A
</td>
</tr><tr>
<td>
Job Title:
</td><td>
N/A
</td>
</tr><tr>
<td>
Location:
</td><td>
N/A
</td>
</tr>
</table>
</td>
<td style="width:50px;vertical-align:top;">
<img src="/images/user_popup.jpg" border="0" width="48" height="48"/>
</td>
</tr>
</table>
</div>
</div>
</td>
In the above example, the Last Name is Demo1, the First Name is Test, and the Email is Demo1#Test.com, and the input id for the checkbox is ctl00_ctl00_all_content_all_content_content_ucUserSearch_gvSearchResults_ctl03_SelectCheckBox.
My question is, how do I identify the input id after I've identified table row? Or, perhaps that's impossible and I'm going about this the wrong way? Any thoughts will be much appreciated.
Edit
This is what I tried that gives me the Runtime error (Object variable or With block variable not set):
trow.Cells(0).getElementsByTagName("input")(0).Click
I also tried this:
set input = trow.Cells(0).getElementsByTagName("input")(0)
input.Click
And finally, both these produce the same error:
Debug.Print trow.Cells(0).getElementsByTagName("input")(0).innerText
Debug.Print trow.Cells(0).getElementsByTagName("input")(0)
This is the output of the Debug.Print in my original code:
Demo1, Test
E-mail: Demo1#Test.com
Employee ID: N/A
Job Title: N/A
Location: N/A
The only pieces I care about (in the output) are the first two lines, the email and name of the individual.
This test worked for me. Looks like the rows you want all have class="griditem", so you can check all table rows for that class name. When you find a match on that and on your cell values, you should be able to find the checkbox as shown.
Sub Tester()
Dim d As New HTMLDocument, trs, rw
d.body.innerHTML = _
"<section><table><tr class='griditem'><td>" & _
"<input type='checkbox' id='id_1'></td>" & _
"<td>Foo</td></tr><tr class='griditem'><td>" & _
"<input type='checkbox' id='id_2'></td>" & _
"<td>Bar</td></tr></table></section>"
Set trs = d.getElementsByTagName("tr")
For Each rw In trs
If rw.className = "griditem" Then
'check cell values for match....
Debug.Print rw.Cells(0).getElementsByTagName("input")(0).ID
End If
Next rw
End Sub
Give a try to this.
Set ElementCol = ie.Document.getElementsByTagName("input")
For Each btnInput In ElementCol
'your code here
Next btnInput

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another

This is the search-process.asp file, I have a main page with a search box that links to this and uses search terms to search my database.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>UNIBOOK - Your facebook alternative - but with no adverts..!</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/unibookStyle.css" />
<%# Language=VBScript %>
<%
set conx=server.CreateObject("adodb.connection")
conx.Provider="Microsoft.ACE.OLEDB.12.0"
conx.Open Server.Mappath("db/unibookv2.mdb")
set userRs=server.CreateObject("adodb.recordset")
userRs.Open "SELECT * FROM ubuser WHERE usr_firstname LIKE '%" & request("searchinput") & "%' OR usr_lastname LIKE '%" & request("searchinput") & "%' ORDER BY '%" & request("orderlist") & "%' ",conx, adOpenkeyset, AdLockOptimistic
%>
<!-- #include FILE="include/header.asp") -->
<div id="container"><!-- start container -->
<h2>USER DATABASE</h2>
<!-- start of dynamic html page -->
<h2>ASP Search Results ordered by : <%=request("orderlist")%></h2>
<%="<b>Search string:</b> " & searchinput & "<br />"%>
<hr align="left" width="658" />
<%if NOT userRs.EOF Then%>
<!-- start of html table -->
<table border="0" width="758" cellspacing="0" cellpadding="3">
<!-- create the first (heading) row in standard HTML -->
<tr class="tableheading">
<td><b>Usr_id</b></td><td><b>firstname</b></td><td> <b>lastname</b></td><td> </td>
<td><b>Usr_id</b></td><td><b>firstname</b></td><td> <b>lastname</b></td><td> </td>
</tr>
<% counter=0 %>
<%Do While Not userRs.EOF
counter=counter+1
if ((counter mod 2)= 1) Then%>
<tr>
<td>
<%=userRs("usr_id") & " "%>
</td>
<td>
<%=userRs("usr_firstname") %>
</td>
<td>
<%=userRs("usr_lastname") %>
</td>
<%else%>
<td>
<!-- display the name of the mountain -->
<%=userRs("usr_id") & " "%>
</td>
<td>
<!-- some comment here -->
<%=userRs("usr_firstname") %>
</td>
<td>
<%=userRs("usr_lastname") %>
</td>
</tr>
<%end if%>
<%userRs.MoveNext
LOOP%>
</table>
<%else%>
<!-- remember to provide a message if the search is not successful -->
<h3>Sorry your search was unsuccessful, please retry</h3>
<%end if%>
<p> </p>
<hr align="left" width="658">
<input type="button" value="< Back to Search Page" OnClick="top.location='default.asp'">
<!-- #include FILE="include/sidebar.asp") -->
</div><!-- end main page content -->
<%
' tidy up any ASP objects used to free web server resources...
userRs.close
set userRs=nothing
set conx=nothing
%>
<!-- #include FILE="include/footer.asp") -->
</body>
</html>
I am getting this error and am not sure if it is the SQL or ASP
ADODB.Recordset error '800a0bb9'
Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
/student/s0190204/part2/search-process.asp, line 17
Are you including the definitions for adOpenkeyset, AdLockOptimistic etc... Its usually in a file called adovbs.inc, but you could add them to other include files in your page..
An unterminated string constant can be caused by an apostrophe in the search input. That is one of the many problems that can be solved by using query parameters.