Is possible to use the code-behind technique out o

Results 1 to 2 of 2

Thread: Is possible to use the code-behind technique out o

  1. #1
    Join Date
    Dec 1969

    Default Is possible to use the code-behind technique out o

    When trying to run an aspx page with a code-behind file, the compiler halts and tells me:<BR><BR>Compiler Error Message: BC30451: Name &#039;Now&#039; is not declared.<BR><BR>&#039;Now&#039; is nothing else than the "run of the mill" VB function, which works fine in code-inside flavor.<BR><BR>My code-behind file looks like this, more or less:<BR><BR>Imports System<BR>Imports System.Web.UI<BR>Imports System.Web.UI.WebControls<BR>Imports System.Web.UI.HtmlControls<BR>imports System.Data<BR>imports System.Data.SqlClient<BR><BR>Public Class myCodeBehind<BR>Inherits Page<BR><BR>Protected WithEvents lblError As Label<BR>Protected WithEvents Label3 As Label <BR>Protected WithEvents TxtNewPass As TextBox<BR>Protected WithEvents cmdChPass As Button<BR>Protected WithEvents TxtPass As TextBox<BR>Protected WithEvents TxtUN As TextBox<BR><BR> Sub Page_Load()<BR> Response.CacheControl = "no-cache"<BR> Response.AddHeader( "Pragma", "no-cache")<BR> Response.Expires = -1<BR> End Sub<BR><BR> Sub cmdOK_Click(sender As Object, e As EventArgs)<BR><BR> Dim strSQL, strMySelf As String<BR> Dim txtLogin As Date<BR> Dim txtUser, strFirstLast, txtCat As Object<BR> Dim rstHasRows As Boolean<BR> Dim cnn As SqlConnection<BR> Dim ocm As SqlCommand<BR> Dim rst As SqlDataReader<BR><BR> strMySelf = "theAuthor" <BR> lblError.Visible = False<BR> cnn = New SqlConnection("Some connection;")<BR> cnn.Open()<BR><BR> ocm = New SqlCommand()<BR> ocm.Connection = cnn<BR> ocm.CommandTimeout = 1200<BR><BR> strSQL = "some query"<BR> ocm.CommandText = strSQL<BR> rst = ocm.ExecuteReader()<BR> rstHasRows = rst.HasRows<BR><BR> If rstHasRows Then<BR> rst.Read()<BR> txtUser = rst("field_1")<BR> txtLogin = Now &#039;so far, the offending line<BR> txtCat = rst("field_2")<BR> strFirstLast = rst("field_3")<BR> End If<BR><BR> rst.Close()<BR><BR> If rstHasRows = True Or txtUN.Text = strMySelf Then<BR> If TxtNewPass.Visible = False Then<BR> strSQL = "some query"<BR> Else<BR> If Len(Trim(txtNewPass.Text)) &#060;&#062; 0 Then<BR> strSQL = "other query"<BR> Else<BR> strSQL = "yet another query"<BR> End If<BR> End If<BR> ocm.CommandText = strSQL<BR> ocm.ExecuteNonQuery()<BR> strSQL = "still a query"<BR> ocm.CommandText = strSQL<BR> ocm.ExecuteNonQuery()<BR> <BR> Session("User") = txtUser<BR> Session("Login") = txtLogin<BR><BR> DeleteOldTables()<BR> Server.Transfer("nextpage.aspx")<BR> Else<BR> strSQL = "query"<BR> ocm.CommandText = strSQL<BR> rst = ocm.ExecuteReader()<BR> lblError.Visible = True<BR> If rst.HasRows = True Then<BR> lblError.Text = "User Already Logged .."<BR> Else<BR> lblError.Text = "Incorrect User Name and/or Password. Try again .."<BR> End If<BR> End If<BR> End Sub<BR><BR> Sub cmdChPass_Click(sender As Object, e As EventArgs)<BR> lblError.Visible = False<BR> Label3.Visible = True<BR> TxtNewPass.Visible = True<BR> cmdChPass.Visible = False<BR> End Sub<BR><BR> Sub cmdCancel_Click(sender As Object, e As EventArgs)<BR> Response.Redirect("lastpage.aspx?user=" & Convert.ToString(Session("User")))<BR> End Sub<BR><BR> Sub DeleteOldTables()<BR> Dim thisUser As String<BR> thisUser = Convert.ToString(Session("User"))<BR><BR> DeleteTable("table A " & thisUser )<BR> DeleteTable("table B " & thisUser )<BR> ....<BR> DeleteTable("table Z " & thisUser )<BR> End Sub<BR><BR> Sub DeleteTable(tblName AS String)<BR><BR> Dim cnn As SqlConnection<BR> Dim ocm As SqlCommand<BR> Dim rst As SqlDataReader<BR> Dim HRows As Boolean<BR><BR> cnn = New SqlConnection("Some connection;")<BR> cnn.Open()<BR> ocm = New SqlCommand()<BR> ocm.Connection = cnn<BR><BR> ocm.CommandText = "SELECT name FROM sysobjects WHERE name = &#039;" & tblName & "&#039;"<BR> rst = ocm.ExecuteReader()<BR> HRows = rst.HasRows<BR> rst.Close()<BR> If HRows Then<BR> ocm.CommandText = "DROP TABLE [" & tblName & "]"<BR> ocm.ExecuteNonQuery()<BR> End If<BR> cnn.Close()<BR> End Sub<BR><BR>End Class<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: Is possible to use the code-behind technique o

    Use Date.Now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts