Hi I am very new to HTML and ASP.net. I am attempting to complete this page and am having a small issue. I have a search page where a user will enter a job number and the webpage will display generated table from SQL. In 2 of the columns I have it generating
checkboxes and I want to be able to change the value of the field in SQL where the checkboxes are checked by using a query. Everytime I try to put in "oncheck= " I get an error saying my connection string is undefined. The code works fine without this task
implemented Here is some of my code and thank you in advance for taking some time.
qry = ("SELECT * FROM [EDIT_8-23-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry1 = ("SELECT * FROM [EDIT_11-3-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry2 = ("SELECT * FROM [EDIT_11-8-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry3 = ("UPDATE [EDIT_8-23-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry4 = ("UPDATE [EDIT_11-3-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry5 = ("UPDATE [EDIT_11-8-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry6 = ("UPDATE [EDIT_8-23-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry7 = ("UPDATE [EDIT_11-3-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry8 = ("UPDATE [EDIT_11-8-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
If SI = "H012531" Or SI = "R012726" Or SI = "F012664" Or SI = "F012358" Or SI = "L012785" Or SI = "H012859" Or SI = "H012679" Or SI = "V012670" Or SI = "R012726" Then
For Each f In RS.fields
If f.name = "FI" Then
Response.Write("<td><br><input type=checkbox Name=CB1 value=A AutoPostBack=true>" & f.value & "</br></td>")
ElseIf f.name = "SO" Then
Response.Write("<td><br><input type=checkbox name=CB1 value=b>" & f.value & "</br></td>")
Else
Response.Write("<td><br>" & f.value & "</br></td>")
End If
On postback (search button's click event or somthing like that), you may check for the values of the check boxes, if they are checked, set value to true else false
You have to specify the connection string like below ,
Dim conn As New SqlClient.SqlConnection()
Dim cmd As New SqlClient.SqlCommand()
conn.ConnectionString = "Data Source=(local);Initial Catalog=myDatabase;Integrated Security=SSPI"
conn.Open()
Please mark the replies as answers if they help or unmark if not.
Thank you for the link to the other forum I will check it out. I have the connection string specified earlier in my code:
(I have erased the credentials)
Dim conn
conn = Server.CreateObject("ADODB.Connection")
conn.open("DSN=;UID=;PWD=;DATABASE=")
The code works fine it is just the checkbox that is not working properly. If i want to display the data from SQL it will let me. When I select a checkbox it gives me an error but they do generate based off of the SQL table selected if that makes sense.
The code works fine it is just the checkbox that is not working properly. If i want to display the data from SQL it will let me. When I select a checkbox it gives me an error but they do generate based off of the SQL table selected if that makes sense.
Hi,
Would you please tell us the query you used when you call ADODB in the checkbox?
Best Regards,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
qry = ("SELECT * FROM [EDIT_8-23-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry1 = ("SELECT * FROM [EDIT_11-3-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry2 = ("SELECT * FROM [EDIT_11-8-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry3 = ("UPDATE [EDIT_8-23-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry4 = ("UPDATE [EDIT_11-3-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry5 = ("UPDATE [EDIT_11-8-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry6 = ("UPDATE [EDIT_8-23-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry7 = ("UPDATE [EDIT_11-3-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry8 = ("UPDATE [EDIT_11-8-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
If SI = "H012531" Or SI = "R012726" Or SI = "F012664" Or SI = "F012358" Or SI = "L012785" Or SI = "H012859" Or SI = "H012679" Or SI = "V012670" Or SI = "R012726" Then
For Each f In RS.fields
If f.name = "FI" Then
Response.Write("<td><br><input type=checkbox Nnme=CB2 value=CB2 runat=server onClick=check(this)>" & f.value & "</br></td>")
ElseIf f.name = "SO" Then
Response.Write("<td><br><input type=checkbox name=CB1 value=CB1>" & f.value & "</br></td>")
Else
Response.Write("<td><br>" & f.value & "</br></td>")
End If
Next
RS.MoveNext()
I have tried:
If CB2.checked Then
RS = conn.execute(qry3)
End If
But it says that CB2 is not declared. Currently I have been trying this instead:
If f.name = "FI" Then
Response.Write("<td><br>" & f.value & "</br></td>")
%>
<input type = "checkbox" id = "CB3" runat = "server">
<%
Else
Response.Write("<td><br>" & f.value & "</br></td>")
End If
Next
RS.MoveNext()
If CB3.Checked Then
RS = conn.execute(qry4)
End If
Loop
It recognizes my checkbox (CB3) but does not execute anything.
Panj27
0 Points
5 Posts
Checkbox
Jan 07, 2013 02:34 PM|LINK
Hi I am very new to HTML and ASP.net. I am attempting to complete this page and am having a small issue. I have a search page where a user will enter a job number and the webpage will display generated table from SQL. In 2 of the columns I have it generating checkboxes and I want to be able to change the value of the field in SQL where the checkboxes are checked by using a query. Everytime I try to put in "oncheck= " I get an error saying my connection string is undefined. The code works fine without this task implemented Here is some of my code and thank you in advance for taking some time.
<%
Dim SI, qry, qry1, qry2, qry3, qry4, qry5, qry6, qry7, qry8
SI = Request.Form("srch")
qry = ("SELECT * FROM [EDIT_8-23-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry1 = ("SELECT * FROM [EDIT_11-3-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry2 = ("SELECT * FROM [EDIT_11-8-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry3 = ("UPDATE [EDIT_8-23-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry4 = ("UPDATE [EDIT_11-3-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry5 = ("UPDATE [EDIT_11-8-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry6 = ("UPDATE [EDIT_8-23-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry7 = ("UPDATE [EDIT_11-3-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry8 = ("UPDATE [EDIT_11-8-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
If SI = "H012531" Or SI = "R012726" Or SI = "F012664" Or SI = "F012358" Or SI = "L012785" Or SI = "H012859" Or SI = "H012679" Or SI = "V012670" Or SI = "R012726" Then
RS = conn.Execute(qry)
%>
<table id="table1" border="2" width="135%" bordercolor=BLUE>
<form name="form1" onsubmit="return checkCheckboxes(abc)">
<%
For Each f In RS.Fields
Response.Write("<td><b>" & f.Name & "</b></td>")
Next
Do While Not RS.EOF
Response.Write("<tr>")
For Each f In RS.fields
If f.name = "FI" Then
Response.Write("<td><br><input type=checkbox Name=CB1 value=A AutoPostBack=true>" & f.value & "</br></td>")
ElseIf f.name = "SO" Then
Response.Write("<td><br><input type=checkbox name=CB1 value=b>" & f.value & "</br></td>")
Else
Response.Write("<td><br>" & f.value & "</br></td>")
End If
Next
RS.MoveNext()
aarsh
Participant
1543 Points
426 Posts
Re: Checkbox
Jan 07, 2013 02:48 PM|LINK
On postback (search button's click event or somthing like that), you may check for the values of the check boxes, if they are checked, set value to true else false
Panj27
0 Points
5 Posts
Re: Checkbox
Jan 07, 2013 02:52 PM|LINK
Ive tried that but for some reason it does not recognize my checkbox as existing. it says CB1 is not declared before I even try to run the program.
paindaasp
Star
12050 Points
2034 Posts
Re: Checkbox
Jan 07, 2013 05:25 PM|LINK
Unless I'm missing something here, you have ASP code, not ASP.NET code.
Panj27
0 Points
5 Posts
Re: Checkbox
Jan 07, 2013 06:10 PM|LINK
You are right I did mean ASP sorry about that.
paindaasp
Star
12050 Points
2034 Posts
Re: Checkbox
Jan 07, 2013 09:29 PM|LINK
Perhaps this forum would be better for your question:
http://forums.aspfree.com/
sen338
Member
498 Points
118 Posts
Re: Checkbox
Jan 07, 2013 09:36 PM|LINK
You have to specify the connection string like below ,
Dim conn As New SqlClient.SqlConnection()
Dim cmd As New SqlClient.SqlCommand()
conn.ConnectionString = "Data Source=(local);Initial Catalog=myDatabase;Integrated Security=SSPI"
conn.Open()
Panj27
0 Points
5 Posts
Re: Checkbox
Jan 08, 2013 02:01 PM|LINK
Thank you for the link to the other forum I will check it out. I have the connection string specified earlier in my code:
(I have erased the credentials)
Dim conn
conn = Server.CreateObject("ADODB.Connection")
conn.open("DSN=;UID=;PWD=;DATABASE=")
The code works fine it is just the checkbox that is not working properly. If i want to display the data from SQL it will let me. When I select a checkbox it gives me an error but they do generate based off of the SQL table selected if that makes sense.
Chen Yu - MS...
All-Star
21569 Points
2493 Posts
Microsoft
Re: Checkbox
Jan 15, 2013 06:28 AM|LINK
Hi,
Would you please tell us the query you used when you call ADODB in the checkbox?
Best Regards,
Feedback to us
Develop and promote your apps in Windows Store
Panj27
0 Points
5 Posts
Re: Checkbox
Jan 15, 2013 01:52 PM|LINK
<% Response.Buffer = True%>
<%
Dim RS
RS = Server.CreateObject("ADODB.RecordSet")
%>
<!DOCTYPE html PUBLIC>
<?xml version="1.0"?>
<%@ Page Language="VB" Debug="True" aspcompat="true"%>
<%@ Import Namespace="System.Data" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<xsl:output method='html'/>
<head>
<title> Table Update </title>
<%
Dim conn
conn = Server.CreateObject("ADODB.Connection")
conn.open("DSN=;UID=;PWD=;DATABASE=") //deleted credentials
%>
<script type="text/javascript" language="javascript">
function fcheck() {
document.getElementById("CB2")
if (checkbox((CB2).checked == true) {
(RS = conn.execute(qry3))
}
}
</script>
</head>
</head><form id="Formm" runat="server">
<label> Please Enter an Order Number to Update: </label>
<p>
<textarea name="srch" rows="1" cols="20" ></textarea>
</p>
<p>
<input type="submit" name="Submit" value="Display" />
<input type="Button" name="Update" value="Update" onclick=""/>
</p>
</form>
<body bgcolor =silver>
<%
Dim SI, qry, qry1, qry2, qry3, qry4, qry5, qry6, qry7, qry8
SI = Request.Form("srch")
qry = ("SELECT * FROM [EDIT_8-23-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry1 = ("SELECT * FROM [EDIT_11-3-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry2 = ("SELECT * FROM [EDIT_11-8-2012] WHERE [VBAK-VBELN] = '" & SI & "'")
qry3 = ("UPDATE [EDIT_8-23-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry4 = ("UPDATE [EDIT_11-3-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry5 = ("UPDATE [EDIT_11-8-2012] SET [FI] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry6 = ("UPDATE [EDIT_8-23-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry7 = ("UPDATE [EDIT_11-3-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
qry8 = ("UPDATE [EDIT_11-8-2012] SET [SO] = 'NO' WHERE [VBAK-VBELN] = '" & SI & "'")
If SI = "H012531" Or SI = "R012726" Or SI = "F012664" Or SI = "F012358" Or SI = "L012785" Or SI = "H012859" Or SI = "H012679" Or SI = "V012670" Or SI = "R012726" Then
RS = conn.Execute(qry)
%>
<table id="table1" border="2" width="135%" bordercolor=BLUE>
<form>
<%
For Each f In RS.Fields
Response.Write("<td><b>" & f.Name & "</b></td>")
Next
Do While Not RS.EOF
Response.Write("<tr>")
For Each f In RS.fields
If f.name = "FI" Then
Response.Write("<td><br><input type=checkbox Nnme=CB2 value=CB2 runat=server onClick=check(this)>" & f.value & "</br></td>")
ElseIf f.name = "SO" Then
Response.Write("<td><br><input type=checkbox name=CB1 value=CB1>" & f.value & "</br></td>")
Else
Response.Write("<td><br>" & f.value & "</br></td>")
End If
Next
RS.MoveNext()
I have tried:
If CB2.checked Then
RS = conn.execute(qry3)
End If
But it says that CB2 is not declared. Currently I have been trying this instead:
If f.name = "FI" Then
Response.Write("<td><br>" & f.value & "</br></td>")
%>
<input type = "checkbox" id = "CB3" runat = "server">
<%
Else
Response.Write("<td><br>" & f.value & "</br></td>")
End If
Next
RS.MoveNext()
If CB3.Checked Then
RS = conn.execute(qry4)
End If
Loop
It recognizes my checkbox (CB3) but does not execute anything.