two more noob questions sorry.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jobs

    #1

    two more noob questions sorry.



    1. How do I pass a subroutine a reference of an object?

    For example I have variable datef type datetime. I want to pass to pass
    datef the variable, not it's value to the sub?


    2. In ADO.NET, how can I see what the parsed value of of a SQL command
    is after @parameters have been passed in?


    Thank you!

  • lord.zoltar@gmail.com

    #2
    Re: two more noob questions sorry.



    On Jan 24, 10:38 am, "jobs" <j...@webdos.co mwrote:
    1. How do I pass a subroutine a reference of an object?
    >
    For example I have variable datef type datetime. I want to pass to pass
    datef the variable, not it's value to the sub?
    >
    The ByRef keyword. Use it in the function's parameter list:
    Public Function myFunc(ByRef something As Object)
    ......
    ......
    End Function

    ByVal is the default, for passing by value

    Comment

    • rowe_newsgroups

      #3
      Re: two more noob questions sorry.

      2. In ADO.NET, how can I see what the parsed value of of a SQL command
      is after @parameters have been passed in?
      Not sure what you mean here, are you looking for the values returned
      when the command executes? If so do this:

      Dim com As New SqlClient.SqlCo mmand()
      ' Do whatever you need to with the command (set parameters,
      active connection, etc)
      Dim dr As SqlClient.SqlDa taReader = com.ExecuteRead er()

      While (dr.Read())
      Console.WriteLi ne(dr.GetString (0)) ' Replace 0 with
      whichever field you need
      End While

      If not, please try to explain what you are looking for a little better
      and we'll try to help.

      Thanks,

      Seth Rowe


      On Jan 24, 10:38 am, "jobs" <j...@webdos.co mwrote:
      1. How do I pass a subroutine a reference of an object?
      >
      For example I have variable datef type datetime. I want to pass to pass
      datef the variable, not it's value to the sub?
      >
      2. In ADO.NET, how can I see what the parsed value of of a SQL command
      is after @parameters have been passed in?
      >
      Thank you!

      Comment

      • jobs

        #4
        Re: two more noob questions sorry.

        Thank you.

        On Jan 24, 11:13 am, "rowe_newsgroup s" <rowe_em...@yah oo.comwrote:
        If not, please try to explain what you are looking for a little better
        and we'll try to help.
        I'm struggling with dates and ado. I have a sub that will be used to
        update both strings and date fields in a table, and so I want the
        field name in question to be dynamic. So the field type might be string
        or datetime. I'm trying to avoid overloading the sub if possible. The
        string update logic works fine, but I try to use it for dates I get
        this error:


        SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and
        12/31/9999 11:59:59 PM.


        here's the sub:
        Public Sub UpdateJob(ByVal Jobno As Integer, ByVal field As String,
        ByVal Value As Object)
        ...
        SQL = "Update job set " + field + "= @datef where jobno =
        @jobno"
        cmd.Parameters. Add("@datef", SqlDbType.DateT ime).Value =
        CType(Value, DateTime)
        ...
        Dim numrow As Integer = cmd.ExecuteNonQ uery

        when it fails, the sub is called as follows

        UpdateJob(jobno , datef) ... where datef is a datetime field I got
        back from a stored proceddure output.

        datef resolves to :2007-01-24 11:15:06.000 and when I do this manually

        Update job set enddate='2007-01-24 11:15:06.000' where jobno = 2

        it works.

        but if I datef.tostring I get some string with AM / PM which does not
        work.



        and want to see the exact SQL that is being attempted.

        Comment

        • Fabio Z

          #5
          Re: two more noob questions sorry.

          <lord.zoltar@gm ail.comha scritto nel messaggio
          >1. How do I pass a subroutine a reference of an object?
          >>
          >For example I have variable datef type datetime. I want to pass to pass
          >datef the variable, not it's value to the sub?
          >>
          >
          The ByRef keyword.
          Pay attention: DateTime is a Value Type, as all the base types and
          structures (except strings that is something different).

          Reference types (classes) are *always* passed byref and specifying ByRef you
          are making a double indirection of the pointer (the pratical effect is the
          same).




          Comment

          Working...