Rephrase of Newby Question!

J

John Baker

Hi:

This is the only ASP newsgroup I can access using Verizon, and I would like to know a real
basic piece of information. I am totall new to ASP, although I have done HTML coding.

Say I The following code is intended to ask for an individuals HIRE Number and then pass
it on to a query, which returns time data for the week. It doesn't work, and I can only
assume that the way I have set it up, or the way I am attempting to set or refer to the
variable HIREID, is wrong. It would be an immeasurable help if someone could point out my
error and how I can fix it! It would alsoi be helpful to know how I grab the data that
comes from the query so I can display it.

John Baker
CODE:

<%@ Page Language="VB" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI"
Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral,
PublicKeyToken=6f763c9966660626" %>
<script runat="server">

Function MyQueryMethod(ByVal hireNumber As String) As System.Data.DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4;
Data Source=C:\IPT\Test\Tim"& _
"eData.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT
[TimeData].[Thu],
[TimeData].[Sun],
[TimeData].[Fri],
[TimeData].[Wed],
[TimeData].[Sat],
[TimeData].[WeekStart],
[TimeData].[AssocName],
[TimeData].[Task_Key],
[TimeData].[PO],
[TimeData].[Mon],
[TimeData].[Tue],
[TimeData].[HireNumber] FROM [TimeData]
WHERE ([TimeData].[HireNumber] = HIREID)"


Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_hireNumber As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_hireNumber.ParameterName = "HIREID"
dbParam_hireNumber.Value = hireNumber
dbParam_hireNumber.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_hireNumber)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function

</script>
<html>
<head>
</head>
<body>
<!-- Insert content here -->
<p align="center">
<img style="WIDTH: 417px; HEIGHT: 179px" height="216" src="IPT logo clear.jpg"
width="472" />
</p>
<p align="center">
<strong style="FONT-SIZE: x-large"><font color="red">IPT Asociates Timesheet
Recording
Process</font></strong>
</p>
<p align="center">
<strong><font color="#ff0000" size="6"></font></strong>
</p>
<p align="center">
</p>
<center>
<form action="intro1.aspx" method="post">
<h3>Hire Number :
<input id="HIREID" type="text" />
<h3>Password :
<input id="Password" type="text" />
</h3>
</h3>
</form>
</center>
</body>
</html>
 
K

Karl Seguin

John:
Do you get an exception?

I know using the SqlClient you need to specify parameters with an @ I would
guess OledbClient is the same, ala:

WHERE ([TimeData].[HireNumber] = @HIREID)"
....
dbParam_hireNumber.ParameterName = "@HIREID"

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


John Baker said:
Hi:

This is the only ASP newsgroup I can access using Verizon, and I would like to know a real
basic piece of information. I am totall new to ASP, although I have done HTML coding.

Say I The following code is intended to ask for an individuals HIRE Number and then pass
it on to a query, which returns time data for the week. It doesn't work, and I can only
assume that the way I have set it up, or the way I am attempting to set or refer to the
variable HIREID, is wrong. It would be an immeasurable help if someone could point out my
error and how I can fix it! It would alsoi be helpful to know how I grab the data that
comes from the query so I can display it.

John Baker
CODE:

<%@ Page Language="VB" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI"
Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral,
PublicKeyToken=6f763c9966660626" %>
<script runat="server">

Function MyQueryMethod(ByVal hireNumber As String) As System.Data.DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4;
Data Source=C:\IPT\Test\Tim"& _
"eData.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT
[TimeData].[Thu],
[TimeData].[Sun],
[TimeData].[Fri],
[TimeData].[Wed],
[TimeData].[Sat],
[TimeData].[WeekStart],
[TimeData].[AssocName],
[TimeData].[Task_Key],
[TimeData].[PO],
[TimeData].[Mon],
[TimeData].[Tue],
[TimeData].[HireNumber] FROM [TimeData]
WHERE ([TimeData].[HireNumber] = HIREID)"


Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_hireNumber As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_hireNumber.ParameterName = "HIREID"
dbParam_hireNumber.Value = hireNumber
dbParam_hireNumber.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_hireNumber)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function

</script>
<html>
<head>
</head>
<body>
<!-- Insert content here -->
<p align="center">
<img style="WIDTH: 417px; HEIGHT: 179px" height="216" src="IPT logo clear.jpg"
width="472" />
</p>
<p align="center">
<strong style="FONT-SIZE: x-large"><font color="red">IPT Asociates Timesheet
Recording
Process</font></strong>
</p>
<p align="center">
<strong><font color="#ff0000" size="6"></font></strong>
</p>
<p align="center">
</p>
<center>
<form action="intro1.aspx" method="post">
<h3>Hire Number :
<input id="HIREID" type="text" />
<h3>Password :
<input id="Password" type="text" />
</h3>
</h3>
</form>
</center>
</body>
</html>
 
M

Michael C#

Try modifying some of your code like this:

' Basically rename your parameters to start with the @ sign
Dim queryString As String = "SELECT [TimeData].[Thu], " & _
" [TimeData].[Sun], [TimeData].[Fri], [TimeData].[Wed], " & _
" [TimeData].[Sat], [TimeData].[WeekStart], [TimeData].[AssocName], " & _
" [TimeData].[Task_Key], [TimeData].[PO], [TimeData].[Mon], " & _
" [TimeData].[Tue], [TimeData].[HireNumber] " & _
"FROM [TimeData] " & _
"WHERE ([TimeData].[HireNumber] = @HIREID)"

Dim dbCommand As System.Data.IDbCommand = _
New System.Data.OleDb.OleDbCommand(queryString, dbConnection)

dbCommand.Parameters.Add("@HIREID", _
System.Data.OleDb.OleDbType.VarChar, 256).Value = hireNumber

If you add a DataGrid to your form, you can point it at the table in your
DataSet to display:

DataGrid1.DataSource = dataSet.Tables(0)
DataGrid1.DataBind()

Alternatively you can iterate the rows using For Each, and display them
individually, etc.

BTW, you might try pointing your newsreader at news.microsoft.com to get
access to all the ms newsgroups.

Hope that helps,
Michael C#

John Baker said:
Hi:

This is the only ASP newsgroup I can access using Verizon, and I would
like to know a real
basic piece of information. I am totall new to ASP, although I have done
HTML coding.

Say I The following code is intended to ask for an individuals HIRE Number
and then pass
it on to a query, which returns time data for the week. It doesn't work,
and I can only
assume that the way I have set it up, or the way I am attempting to set or
refer to the
variable HIREID, is wrong. It would be an immeasurable help if someone
could point out my
error and how I can fix it! It would alsoi be helpful to know how I grab
the data that
comes from the query so I can display it.

John Baker
CODE:

<%@ Page Language="VB" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI"
Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral,
PublicKeyToken=6f763c9966660626" %>
<script runat="server">

Function MyQueryMethod(ByVal hireNumber As String) As System.Data.DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4;
Data Source=C:\IPT\Test\Tim"& _
"eData.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT
[TimeData].[Thu],
[TimeData].[Sun],
[TimeData].[Fri],
[TimeData].[Wed],
[TimeData].[Sat],
[TimeData].[WeekStart],
[TimeData].[AssocName],
[TimeData].[Task_Key],
[TimeData].[PO],
[TimeData].[Mon],
[TimeData].[Tue],
[TimeData].[HireNumber] FROM [TimeData]
WHERE ([TimeData].[HireNumber] = HIREID)"


Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_hireNumber As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_hireNumber.ParameterName = "HIREID"
dbParam_hireNumber.Value = hireNumber
dbParam_hireNumber.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_hireNumber)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function

</script>
<html>
<head>
</head>
<body>
<!-- Insert content here -->
<p align="center">
<img style="WIDTH: 417px; HEIGHT: 179px" height="216" src="IPT logo
clear.jpg"
width="472" />
</p>
<p align="center">
<strong style="FONT-SIZE: x-large"><font color="red">IPT Asociates
Timesheet
Recording
Process</font></strong>
</p>
<p align="center">
<strong><font color="#ff0000" size="6"></font></strong>
</p>
<p align="center">
</p>
<center>
<form action="intro1.aspx" method="post">
<h3>Hire Number :
<input id="HIREID" type="text" />
<h3>Password :
<input id="Password" type="text" />
</h3>
</h3>
</form>
</center>
</body>
</html>
 
J

John Baker

Gentlemen:

Thank you for your suggestions. Unfortunately following your suggestion, I am getting an
error, as follows::
........................................................................................................
<asp:textbox>
Parser Error: '@INHIRENO' is not a valid identifier.
.........................................................................................................

I assume that this is in the HTML code, but dont know what to do about it.

The code now says:

<%@ Page Language="VB" %>
<script runat="server">

Function GetWeek() As System.Data.DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole
DB Services=-4; Data Source=C:\IPT\Test\Tim"& _
"eData.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT [TimeData].[Thu], [TimeData].[Sun],
[TimeData].[Fri], [TimeData].[Wed], [T"& _
"imeData].[Sat], [TimeData].[WeekStart], [TimeData].[AssocName],
[TimeData].[Task"& _
"Key], [TimeData].[PO], [TimeData].[Mon], [TimeData].[Tue],
[TimeData].[HireNumbe"& _
"r] FROM [TimeData] WHERE ([TimeData].[HireNumber] = @INHIRENO)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function' Insert page code here
Dim dbCommand As System.Data.IDbCommand = _
New System.Data.OleDb.OleDbCommand(queryString, dbConnection)

dbCommand.Parameters.Add("@HIREID", _
System.Data.OleDb.OleDbType.VarChar, 256).Value = hireNumber

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here -->
<p>
</p>
valid
<hr />
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<form runat="server" action="controls3.aspx">
<font face="Verdana">Please enter your Hire #:
<asp:textbox id=@INHIRENO runat="server"></asp:textbox>
<asp:button id="Button1" onclick="EnterBtn_Click" runat="server"
text="Enter"></asp:button>
<p>
<asp:Label id="Message" runat="server"></asp:Label>
</p>
</font>
</form>
</form>
</body>
</html
 
K

Kevin Spencer

If you have Outlook Experss (which comes with every version of Windows), you
have a newsreader, which you can use to go to any Microsoft newsgroup. All
of the public Microsoft newsgroups cqan be found on the msnews.microsoft.com
news server.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

John Baker said:
Hi:

This is the only ASP newsgroup I can access using Verizon, and I would
like to know a real
basic piece of information. I am totall new to ASP, although I have done
HTML coding.

Say I The following code is intended to ask for an individuals HIRE Number
and then pass
it on to a query, which returns time data for the week. It doesn't work,
and I can only
assume that the way I have set it up, or the way I am attempting to set or
refer to the
variable HIREID, is wrong. It would be an immeasurable help if someone
could point out my
error and how I can fix it! It would alsoi be helpful to know how I grab
the data that
comes from the query so I can display it.

John Baker
CODE:

<%@ Page Language="VB" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI"
Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral,
PublicKeyToken=6f763c9966660626" %>
<script runat="server">

Function MyQueryMethod(ByVal hireNumber As String) As System.Data.DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB
Services=-4;
Data Source=C:\IPT\Test\Tim"& _
"eData.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT
[TimeData].[Thu],
[TimeData].[Sun],
[TimeData].[Fri],
[TimeData].[Wed],
[TimeData].[Sat],
[TimeData].[WeekStart],
[TimeData].[AssocName],
[TimeData].[Task_Key],
[TimeData].[PO],
[TimeData].[Mon],
[TimeData].[Tue],
[TimeData].[HireNumber] FROM [TimeData]
WHERE ([TimeData].[HireNumber] = HIREID)"


Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dbParam_hireNumber As System.Data.IDataParameter = New
System.Data.OleDb.OleDbParameter
dbParam_hireNumber.ParameterName = "HIREID"
dbParam_hireNumber.Value = hireNumber
dbParam_hireNumber.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_hireNumber)

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function

</script>
<html>
<head>
</head>
<body>
<!-- Insert content here -->
<p align="center">
<img style="WIDTH: 417px; HEIGHT: 179px" height="216" src="IPT logo
clear.jpg"
width="472" />
</p>
<p align="center">
<strong style="FONT-SIZE: x-large"><font color="red">IPT Asociates
Timesheet
Recording
Process</font></strong>
</p>
<p align="center">
<strong><font color="#ff0000" size="6"></font></strong>
</p>
<p align="center">
</p>
<center>
<form action="intro1.aspx" method="post">
<h3>Hire Number :
<input id="HIREID" type="text" />
<h3>Password :
<input id="Password" type="text" />
</h3>
</h3>
</form>
</center>
</body>
</html>
 
T

teknohippy

Hi:

This is the only ASP newsgroup I can access using Verizon, and I would like to know a real
basic piece of information. I am totall new to ASP, although I have done HTML coding.

It's the correct newsgroup, that's asp.net you are writing by the
looks of it. :)
 
T

teknohippy

Gentlemen:

Thank you for your suggestions. Unfortunately following your suggestion, I am getting an
error, as follows::
.......................................................................................................
<asp:textbox>
Parser Error: '@INHIRENO' is not a valid identifier.
........................................................................................................


Have the text box id be something like id="txtHireNumber"

Now where you build the query just concatonate the text property of
the text box into the query.

eg.

Dim SQLQuery As String

SQLQuery = "SELECT * FROM TimeDate WHERE HireNumber = " &
txtHireNumber.Text & ";"

Assuming the Hire number isn't a string of course.
 
K

Karl Seguin

I'm confused by this question now for some reason. Iain, the code you
provided is pretty dangerous and could very easily lead to an SQL injection.
Always use parameterized values.

John,
it seems like you are adding the @HireId parameter to the command object
AFTER you are executing the code. Also, you name the parameter @HireId when
adding the parameter but @InHireNo in your SQL command. It should look a lo
tmore like:

imports System.Data
imports System.Data.OleDb

Function GetWeek() As DataSet
Dim connectionString As String = "CONNECTION_STRING"
Dim dbConnection As IDbConnection = New OleDbConnection(connectionString)

Dim queryString As String = "SELECT COLUMNS FROM [TimeData] WHERE
([TimeData].[HireNumber] = @Hireid)"
Dim dbCommand As IDbCommand = New OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dbCommand.Parameters.Add("@HireId", SqlDbType.Int).value = hireNumber

Dim dataAdapter As IDbDataAdapter = New OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As DataSet = New DataSet
try
dataAdapter.Fill(dataSet)
Return dataSet
finally
dbCommand.Dispose()
dataAdapter.Dispose()
end try
end function



Note that I importanted System.Data and System.Data.OleDb to make it more
readable. I also added some cleanup code and I changed a bit of the lengthy
content (liek connection string, and SQL statement) to abbreviate it.

Karl
 
M

Michael C#

Where did @INHIREID come from? You called it @HIREID previously. You need
to match up the parameter name in your SQL Statement with the one in the
Parameters.Add() statement.
 
M

Michael C#

P.S. - You put this code:
Dim dbCommand As System.Data.OlebCommand = _
New System.Data.OleDb.OleDbCommand(queryString, dbConnection)

dbCommand.Parameters.Add("@HIREID", _
System.Data.OleDb.OleDbType.VarChar, 256).Value = hireNumber

Outside your function. It was meant to go inside the function, to replace
the more lengthy versions you posted.

Thx

Michael C# said:
Where did @INHIREID come from? You called it @HIREID previously. You
need to match up the parameter name in your SQL Statement with the one in
the Parameters.Add() statement.


John Baker said:
Gentlemen:

Thank you for your suggestions. Unfortunately following your suggestion,
I am getting an
error, as follows::
.......................................................................................................
<asp:textbox>
Parser Error: '@INHIRENO' is not a valid identifier.
........................................................................................................

I assume that this is in the HTML code, but dont know what to do about
it.

The code now says:

<%@ Page Language="VB" %>
<script runat="server">

Function GetWeek() As System.Data.DataSet
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole
DB Services=-4; Data Source=C:\IPT\Test\Tim"& _
"eData.mdb"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.OleDb.OleDbConnection(connectionString)

Dim queryString As String = "SELECT [TimeData].[Thu],
[TimeData].[Sun],
[TimeData].[Fri], [TimeData].[Wed], [T"& _
"imeData].[Sat], [TimeData].[WeekStart], [TimeData].[AssocName],
[TimeData].[Task"& _
"Key], [TimeData].[PO], [TimeData].[Mon], [TimeData].[Tue],
[TimeData].[HireNumbe"& _
"r] FROM [TimeData] WHERE ([TimeData].[HireNumber] = @INHIRENO)"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

Dim dataAdapter As System.Data.IDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New
System.Data.DataSet
dataAdapter.Fill(dataSet)

Return dataSet
End Function' Insert page code here
Dim dbCommand As System.Data.IDbCommand = _
New System.Data.OleDb.OleDbCommand(queryString, dbConnection)

dbCommand.Parameters.Add("@HIREID", _
System.Data.OleDb.OleDbType.VarChar, 256).Value = hireNumber

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<!-- Insert content here -->
<p>
</p>
valid
<hr />
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<p>
</p>
<form runat="server" action="controls3.aspx">
<font face="Verdana">Please enter your Hire #:
<asp:textbox id=@INHIRENO runat="server"></asp:textbox>
<asp:button id="Button1" onclick="EnterBtn_Click"
runat="server"
text="Enter"></asp:button>
<p>
<asp:Label id="Message" runat="server"></asp:Label>
</p>
</font>
</form>
</form>
</body>
</html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top