|
-
Aug 12th, 2002, 09:14 PM
#1
Thread Starter
Junior Member
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
-
Aug 12th, 2002, 10:13 PM
#2
Hyperactive Member
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() & "'"
-
Aug 12th, 2002, 10:22 PM
#3
Thread Starter
Junior Member
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
-
Aug 13th, 2002, 12:50 PM
#4
Hyperactive Member
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 ).
-
Aug 13th, 2002, 03:33 PM
#5
Thread Starter
Junior Member
I am not familiar with that function.
What is the syntax, and where would I use it?
-
Aug 13th, 2002, 03:42 PM
#6
Hyperactive Member
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".
-
Aug 13th, 2002, 04:01 PM
#7
Thread Starter
Junior Member
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?
-
Aug 13th, 2002, 05:16 PM
#8
Hyperactive Member
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.
-
Aug 14th, 2002, 02:53 AM
#9
New Member
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.
-
Aug 14th, 2002, 04:41 AM
#10
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
-
Aug 14th, 2002, 04:52 AM
#11
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|