J
Jim via DotNetMonster.com
Hi,
I need to pass the value of a variable from one function to another but I
don't seem to get the value. I declare the variable outside all functions.
What I'm trying to do is that when the button is clicked, check to see if
the record exists using input from a form. I want to pass that variable to
the button click Sub because if it doesn't exist then the record is
inserted and the user is directed to a different page. The variable I'm
checking is recExists.
Thanks for any help.
This is my code
<script runat="server">
Dim recExists as Integer
Dim IntLessonID as Integer
Sub Page_Load(sender As Object, e As EventArgs)
If Page.IsPostBack = False Then
IntLessonID = Request.QueryString( "LessonID" )
Page.Databind()
End If
End Sub
Function RecordExists(ByVal PageNumber As Integer, ByVal LessonID As
Integer) As System.Data.IDataReader
Dim connectionString As String = "server='(local)';
trusted_connection=true; database='xx'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [tblPage].[PageNumber], [tblPage].
[LessonID] FROM [tblPage] WHERE (([t"& _
"blPage].[PageNumber] = @PageNumber) AND ([tblPage].[LessonID] =
@LessonID))"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_PageNumber As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_PageNumber.ParameterName = "@PageNumber"
dbParam_PageNumber.Value = PageNumber
dbParam_PageNumber.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_PageNumber)
Dim dbParam_LessonID As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_LessonID.ParameterName = "@LessonID"
dbParam_LessonID.Value = LessonID
dbParam_LessonID.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_LessonID)
dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
If (dataReader.Read = True) Then
recexists = 1
msgLabel.Text = "Record exists"
Else
recexists = 0
'insert record code here
End If
Return dataReader
End Function
Sub FinishButton_Click(sender As Object, e As EventArgs)
IntLessonID = Request.QueryString( "LessonID" )
RecordExists (fPageNumber.SelectedItem.Value, IntLessonID)
If RecExists = 1 Then
Response.Write("Record Exists")
Else
Response.Write("Record doesn't Exist")
End If
End Sub
</script>
<html>
<head>
<link href="assets/style_admin.css" type="text/css" rel="stylesheet" />
</head>
<body leftmargin="0" topmargin="0">
<form runat="server">
Page Number:
<aspropDownList id="fPageNumber" runat="server">
<asp:ListItem Value="0"> </asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
</aspropDownList>
<br>
<asp:Button id="FinishButton" onclick="FinishButton_Click"
runat="server" Text="Finish"></asp:Button>
</form>
</body>
</html>
I need to pass the value of a variable from one function to another but I
don't seem to get the value. I declare the variable outside all functions.
What I'm trying to do is that when the button is clicked, check to see if
the record exists using input from a form. I want to pass that variable to
the button click Sub because if it doesn't exist then the record is
inserted and the user is directed to a different page. The variable I'm
checking is recExists.
Thanks for any help.
This is my code
<script runat="server">
Dim recExists as Integer
Dim IntLessonID as Integer
Sub Page_Load(sender As Object, e As EventArgs)
If Page.IsPostBack = False Then
IntLessonID = Request.QueryString( "LessonID" )
Page.Databind()
End If
End Sub
Function RecordExists(ByVal PageNumber As Integer, ByVal LessonID As
Integer) As System.Data.IDataReader
Dim connectionString As String = "server='(local)';
trusted_connection=true; database='xx'"
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [tblPage].[PageNumber], [tblPage].
[LessonID] FROM [tblPage] WHERE (([t"& _
"blPage].[PageNumber] = @PageNumber) AND ([tblPage].[LessonID] =
@LessonID))"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_PageNumber As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_PageNumber.ParameterName = "@PageNumber"
dbParam_PageNumber.Value = PageNumber
dbParam_PageNumber.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_PageNumber)
Dim dbParam_LessonID As System.Data.IDataParameter = New
System.Data.SqlClient.SqlParameter
dbParam_LessonID.ParameterName = "@LessonID"
dbParam_LessonID.Value = LessonID
dbParam_LessonID.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_LessonID)
dbConnection.Open
Dim dataReader As System.Data.IDataReader =
dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
If (dataReader.Read = True) Then
recexists = 1
msgLabel.Text = "Record exists"
Else
recexists = 0
'insert record code here
End If
Return dataReader
End Function
Sub FinishButton_Click(sender As Object, e As EventArgs)
IntLessonID = Request.QueryString( "LessonID" )
RecordExists (fPageNumber.SelectedItem.Value, IntLessonID)
If RecExists = 1 Then
Response.Write("Record Exists")
Else
Response.Write("Record doesn't Exist")
End If
End Sub
</script>
<html>
<head>
<link href="assets/style_admin.css" type="text/css" rel="stylesheet" />
</head>
<body leftmargin="0" topmargin="0">
<form runat="server">
Page Number:
<aspropDownList id="fPageNumber" runat="server">
<asp:ListItem Value="0"> </asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
</aspropDownList>
<br>
<asp:Button id="FinishButton" onclick="FinishButton_Click"
runat="server" Text="Finish"></asp:Button>
</form>
</body>
</html>