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(sende r As Object, e As EventArgs)
If Page.IsPostBack = False Then
IntLessonID = Request.QuerySt ring( "LessonID" )
Page.Databind()
End If
End Sub
Function RecordExists(By Val PageNumber As Integer, ByVal LessonID As
Integer) As System.Data.IDa taReader
Dim connectionStrin g As String = "server='(local )';
trusted_connect ion=true; database='xx'"
Dim dbConnection As System.Data.IDb Connection = New
System.Data.Sql Client.SqlConne ction(connectio nString)
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.IDb Command = New
System.Data.Sql Client.SqlComma nd
dbCommand.Comma ndText = queryString
dbCommand.Conne ction = dbConnection
Dim dbParam_PageNum ber As System.Data.IDa taParameter = New
System.Data.Sql Client.SqlParam eter
dbParam_PageNum ber.ParameterNa me = "@PageNumbe r"
dbParam_PageNum ber.Value = PageNumber
dbParam_PageNum ber.DbType = System.Data.DbT ype.Int32
dbCommand.Param eters.Add(dbPar am_PageNumber)
Dim dbParam_LessonI D As System.Data.IDa taParameter = New
System.Data.Sql Client.SqlParam eter
dbParam_LessonI D.ParameterName = "@LessonID"
dbParam_LessonI D.Value = LessonID
dbParam_LessonI D.DbType = System.Data.DbT ype.Int32
dbCommand.Param eters.Add(dbPar am_LessonID)
dbConnection.Op en
Dim dataReader As System.Data.IDa taReader =
dbCommand.Execu teReader(System .Data.CommandBe havior.CloseCon nection)
If (dataReader.Rea d = True) Then
recexists = 1
msgLabel.Text = "Record exists"
Else
recexists = 0
'insert record code here
End If
Return dataReader
End Function
Sub FinishButton_Cl ick(sender As Object, e As EventArgs)
IntLessonID = Request.QuerySt ring( "LessonID" )
RecordExists (fPageNumber.Se lectedItem.Valu e, 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:
<asp:DropDownLi st 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>
</asp:DropDownLis t>
<br>
<asp:Button id="FinishButto n" onclick="Finish Button_Click"
runat="server" Text="Finish"></asp:Button>
</form>
</body>
</html>
--
Message posted via http://www.dotnetmonster.com