By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,706 Members | 2,046 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,706 IT Pros & Developers. It's quick & easy.

two more noob questions sorry.

P: n/a


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!

Jan 24 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a


On Jan 24, 10:38 am, "jobs" <j...@webdos.comwrote:
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

Jan 24 '07 #2

P: n/a
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.SqlCommand()
' Do whatever you need to with the command (set parameters,
active connection, etc)
Dim dr As SqlClient.SqlDataReader = com.ExecuteReader()

While (dr.Read())
Console.WriteLine(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.comwrote:
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!
Jan 24 '07 #3

P: n/a
Thank you.

On Jan 24, 11:13 am, "rowe_newsgroups" <rowe_em...@yahoo.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.DateTime).Value =
CType(Value, DateTime)
...
Dim numrow As Integer = cmd.ExecuteNonQuery

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.

Jan 24 '07 #4

P: n/a
<lo*********@gmail.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).


Jan 25 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.