Results 1 to 11 of 11

Thread: Passing variables

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2002
    Posts
    17

    Passing variables

    I am passing a variable from one one to the another e.g.

    Public Sub mysub(ByVal number As Integer)

    cmdsupport = dbconn.CreateCommand
    cmdsupport.CommandText = "select * from supportcall where ID = '" & number & "'"
    dbsupport.Fill(dssupport, "SupportCall")

    However when the program fills the dataset, it crashes warning me that "Additional information: Argument 'Prompt' cannot be converted to type 'String'"

    Do I need to convert the number variable somewhere?

    It is an Access db connection

  2. #2
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261

    Re: Passing variables

    Originally posted by CookieNZ
    I am passing a variable from one one to the another e.g.

    Public Sub mysub(ByVal number As Integer)

    cmdsupport = dbconn.CreateCommand
    cmdsupport.CommandText = "select * from supportcall where ID = '" & number & "'"
    dbsupport.Fill(dssupport, "SupportCall")

    However when the program fills the dataset, it crashes warning me that "Additional information: Argument 'Prompt' cannot be converted to type 'String'"

    Do I need to convert the number variable somewhere?

    It is an Access db connection
    Hmm, I dont think you can concatenate an Integer to a string like that.

    Try this:
    cmdsupport.CommandText = "select * from supportcall where ID = '" & number.ToString() & "'"

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2002
    Posts
    17
    Cheers, but that hasn't help.

    Can I not do anything in the form that the variable is first used e.g:-


    Private Sub btnopencall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopencall.Click

    Dim frmopencall As New supportcalls()

    frmopencall.mysub(txtcallnumber.Text)


    End Sub

  4. #4
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Originally posted by CookieNZ
    Cheers, but that hasn't help.

    Can I not do anything in the form that the variable is first used e.g:-


    Private Sub btnopencall_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnopencall.Click

    Dim frmopencall As New supportcalls()

    frmopencall.mysub(txtcallnumber.Text)


    End Sub
    The MySub procedure you have written accepts an Integer as an argument, and the Text property your passing to it is a String.

    You have to convert it to an Integer first ( you can use the Integer.Parse() function for this ).

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2002
    Posts
    17
    I am not familiar with that function.

    What is the syntax, and where would I use it?

  6. #6
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Originally posted by CookieNZ
    I am not familiar with that function.

    What is the syntax, and where would I use it?
    Aren't you using the VS.NET IDE? The intellisense would tell you this.

    Anyway, use it like this:

    Dim intX as Integer = 123
    Dim strY as String

    strY = Integer.Parse(intX)

    strY now equals the string "123".

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Jun 2002
    Posts
    17
    I use the follow sub:-

    Dim numberint As Integer = number
    Dim numberstr As String

    numberstr = Integer.Parse(numberint)

    cmdsupport = dbconn.CreateCommand

    cmdsupport.CommandText = "select * from supportcall where ID = '" & numberstr & "'"

    MsgBox("Here")

    dbsupport.Fill(dssupport, "SupportCall")

    It displays the "Here" message, then seems to fall over on the fill call, still complaining about the string.

    Any thoughts?

  8. #8
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Originally posted by CookieNZ
    I use the follow sub:-

    Dim numberint As Integer = number
    Dim numberstr As String

    numberstr = Integer.Parse(numberint)

    cmdsupport = dbconn.CreateCommand

    cmdsupport.CommandText = "select * from supportcall where ID = '" & numberstr & "'"

    MsgBox("Here")

    dbsupport.Fill(dssupport, "SupportCall")

    It displays the "Here" message, then seems to fall over on the fill call, still complaining about the string.

    Any thoughts?
    Are you sure that the 'Fill' call accepts arguments of those types in that order? I assume your not using the VS.NET IDE (though you really should, it is awesome), because if you were, you wouldn't be asking these questions (it has a bug-checker built in and it tells you exactly why your program isn't working. The intellisense it has is also an extremely useful tool).

    Hmm, I'm not sure what object 'dbsupport' is, so I cant tell you if your calling it right. Go look at the documentation on msdn.microsoft.com or on your system if you have it.

  9. #9
    New Member Varadero's Avatar
    Join Date
    Aug 2002
    Posts
    7
    This is how i do this thing :
    '-------------------------------------------------------------------------------
    'Usage : Fetches a typed Artist dataset detail row by Table ID
    'Parameters :
    ' ByVal vArtistID as Int32 => The primary key of the row to be fetched
    'Return :
    ' A typed Artist Dataset
    'Authors : Bart Schelkens
    'Reviews :
    'Date Creation: 13/08/2002
    'Modifications:
    ' nr : date : reason
    'Errorhandling:
    'Remarks :
    '-------------------------------------------------------------------------------
    Public Function GetDetailByID(ByVal vArtistID As Int32) As DiscoBar.DataSets.DSArtists

    Return FillDataSet("SELECT * FROM Artists " & _
    "WHERE ArtistID = " & vArtistID.ToString())

    End Function


    '-------------------------------------------------------------------------------
    'Usage : Fetches a typed Artists dataset
    'Parameters :
    ' ByVal vstrCommandText as string => The source sql statement used to fetch the dataset
    'Return :
    ' A typed Artists dataset
    'Authors : Bart Schelkens
    'Reviews :
    'Date Creation: 13/08/2002
    'Modifications:
    ' nr : date : reason
    'Errorhandling:
    'Remarks :
    '-------------------------------------------------------------------------------
    Private Function FillDataSet(ByVal vstrCommandText As String) As DiscoBar.DataSets.DSArtists
    Dim dsData As DiscoBar.DataSets.DSArtists = New DiscoBar.DataSets.DSArtists()
    Dim cmdCommand As OleDbCommand = New OleDbCommand()

    cmdCommand.Connection = mconDB
    cmdCommand.CommandType = CommandType.Text
    cmdCommand.CommandText = vstrCommandText

    mdtaDataAdapter.SelectCommand = cmdCommand
    mdtaDataAdapter.Fill(dsData, "Artists")

    Return dsData
    End Function


    And this seems to be working just fine.

  10. #10
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    If ID is of a numeric type, the quotes are not necesary, and depending on the database you use, it could cause a problem.
    Try removing the quotes around the number:

    cmdsupport.CommandText = "select * from supportcall where ID = " & numberstr

  11. #11
    New Member Varadero's Avatar
    Join Date
    Aug 2002
    Posts
    7
    Originally posted by Frans C
    If ID is of a numeric type, the quotes are not necesary, and depending on the database you use, it could cause a problem.
    Try removing the quotes around the number:

    cmdsupport.CommandText = "select * from supportcall where ID = " & numberstr
    This is the way i do, so i to convert the number to a string, but i don't use the quotes. This works just fine.

    Return FillDataSet("SELECT * FROM Artists WHERE ArtistID = " & vArtistID.ToString())

Posting Permissions

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



Click Here to Expand Forum to Full Width