locked
Name 'Using' is not declared. RRS feed

  • Question

  • User-1051586361 posted

    Hi,


    found just one topic conerning this error, but that did'nt help me, so I open a new thread.


    I get this error when using the code:

                    Using conn As New Data.OleDb.OleDbConnection(connect)
                        using cmd As New Data.OleDb.OleDbCommand(query, conn)
                            cmd.Parameters.AddWithValue("", TBusername.Text)
                            cmd.Parameters.AddWithValue("", TBpassword.Text)
                            conn.Open()
                            Session("User") = TBusername.Text
                            Session.Timeout = 120
                            Dim Datum As String
                            If System.DateTime.Now().Day < 10 Then
                                Datum = "0" & System.DateTime.Now.Day
                            Else
                                Datum = System.DateTime.Now.Day
                            End If
                            If System.DateTime.Now().Month < 10 Then
                                Datum = Datum & "/0" & System.DateTime.Now.Month
                            Else
                                Datum = Datum & "/" & System.DateTime.Now.Month
                            End If
                            Datum = Datum & "/" & System.DateTime.Now.Year
                            Session("Date") = Datum
                            result = DirectCast(cmd.ExecuteScalar(), Integer)
                            conn.Close()
                        End Using
                    End Using


    What could be the reason for this, as in the offline develope environment I had no problems using this code. Or do I need to create a workaround?


    Thanks and regards,

    Henrik

    Wednesday, April 14, 2010 3:08 AM

Answers

  • User-1199946673 posted

    Dim Datum As String
    If System.DateTime.Now().Day < 10 Then
      Datum = "0" & System.DateTime.Now.Day
    Else
      Datum = System.DateTime.Now.Day
    End If
    If System.DateTime.Now().Month < 10 Then
      Datum = Datum & "/0" & System.DateTime.Now.Month
    Else
      Datum = Datum & "/" & System.DateTime.Now.Month
    End If
    Datum = Datum & "/" & System.DateTime.Now.Year

    This can simply be achieved with:

    Datum = System.DateTime.Now.ToString("dd/MM/yyyy")

    But why do you store a string representing the current date in a session variable, instead of the current date as a date:

    Session("Date") = System.DateTime.Today

    Also, it looks to me that you want to implement a login system. Why not use the build in membership provider?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 14, 2010 6:14 AM

All replies

  • User197322208 posted

    Maybe the .NET framewrok is not the same ? If I remeber well, "using" in VB.NET is from 3.5 ...

    Wednesday, April 14, 2010 3:52 AM
  • User-1199946673 posted

    Maybe the .NET framewrok is not the same ? If I remeber well, "using" in VB.NET is from 3.5 ...

     

    No, it was introduced in .NET 2.0

    Wednesday, April 14, 2010 6:03 AM
  • User-1199946673 posted

    Dim Datum As String
    If System.DateTime.Now().Day < 10 Then
      Datum = "0" & System.DateTime.Now.Day
    Else
      Datum = System.DateTime.Now.Day
    End If
    If System.DateTime.Now().Month < 10 Then
      Datum = Datum & "/0" & System.DateTime.Now.Month
    Else
      Datum = Datum & "/" & System.DateTime.Now.Month
    End If
    Datum = Datum & "/" & System.DateTime.Now.Year

    This can simply be achieved with:

    Datum = System.DateTime.Now.ToString("dd/MM/yyyy")

    But why do you store a string representing the current date in a session variable, instead of the current date as a date:

    Session("Date") = System.DateTime.Today

    Also, it looks to me that you want to implement a login system. Why not use the build in membership provider?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 14, 2010 6:14 AM