Last post Nov 06, 2010 06:39 AM by tvince12
Nov 05, 2010 07:25 PM|tvince12|LINK
I have just started a web service as part of a university project. My first method is trying to get all entries in one of the database tables. However when I try to build the solution this is the error I get:
Value of type 'String' cannot be converted to '1-dimensional array of String'
I must admit I do not understand this error at all. Can anyone guide me on this one? Here's my code for the Service.vb class so far and the error is pointing a the "Return events" line:
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
Public Class Service
Public Function GetAllEvents() As String()
Dim conn As New SqlConnection("ConnectionString")
Dim sql As String = "SELECT * FROM BHPInfoEvents"
Dim cmd As New SqlCommand(sql, conn)
Dim events As String = cmd.ExecuteScalar()
I would really appreciate explanations on this to understand where I have gone wrong.
Nov 05, 2010 08:11 PM|SGWellens|LINK
I'm not a VB guy but....
It looks like your function is declared to return an array of strings:
....GetAllEvents() As String()
You are returning just a string.
You probably want:
....GetAllEvents() As String
Nov 06, 2010 06:39 AM|tvince12|LINK
Thanks Steven that's what the problem was. I'm not a VB person either but the lecturer wants all work done in VB. I am more used to C# and some Java, where the order of the words in syntax is slightly different.
Thanks again for your time