asmx won't return JSON - json

I've completely rewritten this old asmx service function but I still can't get it to return JSON. It returns XML, even if I use ajax() and set the datatype and contenttype to json. I'm trying to use this function with Jquery dataTables. And I know there are tons of questions like this but all of them I've found are C# and I was unable to adapt them.
up-to-date pastebin of full asmx file: http://pastebin.com/swXKqgd4
new code
<WebMethod()> _
<WebGet(ResponseFormat:=WebMessageFormat.Json)> _
Public Function rptPendingServerRequests() As Generic.List(Of request)
Dim _conn As SqlConnection = New SqlConnection(connectionString)
Dim _dr As SqlDataReader
Dim Sql As String = String.Empty
Sql += "<My query here>"
Try
Dim _cmd As SqlCommand = New SqlCommand(Sql, _conn)
_conn.Open()
_dr = _cmd.ExecuteReader(CommandBehavior.CloseConnection)
If _dr.HasRows Then
Dim s As request
Dim c As New Generic.List(Of request)
While _dr.Read
s = New request
With s
.requestID = _dr("request_id")
.status = _dr("status")
.requester = _dr("req_by_user_id")
.assignee = _dr("user_id")
.nextAction = _dr("description")
End With
c.Add(s)
End While
Return c
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
_conn.Close()
End Try
End Function
New class
<Serializable()> _
Public Class request
Private _requestID As Integer
Public Property requestID() As Integer
Get
Return _requestID
End Get
Set(ByVal value As Integer)
_requestID = value
End Set
End Property
Private _requester As String
Public Property requester() As String
Get
Return _requester
End Get
Set(ByVal value As String)
_requester = value
End Set
End Property
Private _requestDate As Date
Public Property requestDate() As Date
Get
Return _requestDate
End Get
Set(ByVal value As Date)
_requestDate = value
End Set
End Property
Private _status As Integer
Public Property status() As Integer
Get
Return _status
End Get
Set(ByVal value As Integer)
_status = value
End Set
End Property
Private _assignee As String
Public Property assignee() As String
Get
Return _assignee
End Get
Set(ByVal value As String)
_assignee = value
End Set
End Property
Private _nextAction As String
Public Property nextAction() As String
Get
Return _nextAction
End Get
Set(ByVal value As String)
_nextAction = value
End Set
End Property
End Class
Original Code
<WebMethod()> _
<WebGet(ResponseFormat:=WebMessageFormat.Json)> _
Public Function rptPendingServerRequestsOld() As DataSet
Dim connection As SqlConnection
Dim command As SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New DataSet
Dim sql As String
sql = ""
sql += "<MY query here>"
connection = New SqlConnection(connectionString)
Try
connection.Open()
command = New SqlCommand(sql, connection)
adapter.SelectCommand = command
adapter.Fill(ds)
adapter.Dispose()
command.Dispose()
connection.Close()
Return ds
Catch ex As Exception
End Try
End Function
Client
$('#report').dataTable({
"bProcessing": true,
"sAjaxSource": 'reportdata.asmx/rptPendingServerRequests'
});

Since you're calling this method from JS instead of
<WebGet(ResponseFormat:=WebMessageFormat.Json)>
use
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)>
attribute. Also don't forget to mark your WebService class with
<ScriptService()>
attribute.

Change this line.
Public Function rptPendingServerRequests() As Generic.List(Of request)
to
Public Function rptPendingServerRequests() As String.

Related

'The node must be of type 'JsonObject'.'

I'm trying to parse this Json
With the code:
Dim streamData As Stream = Nothing
Using http As New HttpClient
Dim url As String = "https://api.hotbit.io/api/v1/market.deals?market=KIBA/USDT&limit=150&last_id=1521100930&api_key=44812d8f-66d3-01c0-94c3b29305040b03&sign=98EEC3D69D3F70F9BDFED901984B2AA4"
Dim t As Task(Of Stream) = http.GetStreamAsync(url)
streamData = t.Result
End Using
Dim jsonResponse As JsonNode = JsonNode.Parse(streamData)
Dim result As JsonObject = jsonResponse("result").AsObject
Dim c As String = String.Empty
For Each kvp In result.AsEnumerable
c &= kvp.Value("price").ToString & vbCr
Next
RichTextBox1.Text = c
End Sub
but I keep getting the error at debug
The node must be of type 'JsonObject'.'
on the line
Dim result As JsonObject = jsonResponse("result").AsObject
How it comes it gives an error If I'm already trying to parse it as a Jsonobject?
Thanks
Give a go at this..
Paste this into a new class file:
Namespace HotBit
Partial Public Class TradeCollection
<JsonProperty("error")>
Public Property [Error] As Object
<JsonProperty("result")>
Public Property Result As List(Of Result)
<JsonProperty("id")>
Public Property Id As Long
End Class
Partial Public Class Result
<JsonProperty("id")>
Public Property Id As Long
<JsonProperty("time")>
Public Property Time As Long
<JsonProperty("price")>
Public Property Price As String
<JsonProperty("amount")>
<JsonConverter(GetType(ParseStringConverter))>
Public Property Amount As Long
<JsonProperty("type")>
Public Property Type As TypeEnum
End Class
Public Enum TypeEnum
Buy
Sell
End Enum
Partial Public Class TradeCollection
Public Shared Function FromJson(ByVal json As String) As TradeCollection
Return JsonConvert.DeserializeObject(Of TradeCollection)(json, Settings)
End Function
End Class
Public Module Serialize
<Extension()>
Public Function ToJson(ByVal self As TradeCollection) As String
Return JsonConvert.SerializeObject(self, Settings)
End Function
End Module
Friend Module Converter
Public ReadOnly Settings As JsonSerializerSettings = New JsonSerializerSettings With {
.MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
.DateParseHandling = DateParseHandling.None
}
End Module
Friend Class ParseStringConverter
Inherits JsonConverter
Public Overrides Function CanConvert(ByVal t As Type) As Boolean
Return t Is GetType(Long) OrElse t Is GetType(Long?)
End Function
Public Overrides Function ReadJson(ByVal reader As JsonReader, ByVal t As Type, ByVal existingValue As Object, ByVal serializer As JsonSerializer) As Object
If reader.TokenType = JsonToken.Null Then Return Nothing
Dim value = serializer.Deserialize(Of String)(reader)
Dim l As Long
If Long.TryParse(value, l) Then
Return l
End If
Throw New Exception("Cannot unmarshal type long")
End Function
Public Overrides Sub WriteJson(ByVal writer As JsonWriter, ByVal untypedValue As Object, ByVal serializer As JsonSerializer)
If untypedValue Is Nothing Then
serializer.Serialize(writer, Nothing)
Return
End If
Dim value = CLng(untypedValue)
serializer.Serialize(writer, value.ToString())
Return
End Sub
Public Shared ReadOnly Singleton As ParseStringConverter = New ParseStringConverter()
End Class
Friend Class TypeEnumConverter
Inherits JsonConverter
Public Overrides Function CanConvert(ByVal t As Type) As Boolean
Return t Is GetType(TypeEnum) OrElse t Is GetType(TypeEnum?)
End Function
Public Overrides Function ReadJson(ByVal reader As JsonReader, ByVal t As Type, ByVal existingValue As Object, ByVal serializer As JsonSerializer) As Object
If reader.TokenType = JsonToken.Null Then Return Nothing
Dim value = serializer.Deserialize(Of String)(reader)
Select Case value
Case "buy"
Return TypeEnum.Buy
Case "sell"
Return TypeEnum.Sell
End Select
Throw New Exception("Cannot unmarshal type TypeEnum")
End Function
Public Overrides Sub WriteJson(ByVal writer As JsonWriter, ByVal untypedValue As Object, ByVal serializer As JsonSerializer)
If untypedValue Is Nothing Then
serializer.Serialize(writer, Nothing)
Return
End If
Dim value = CType(untypedValue, TypeEnum)
Select Case value
Case TypeEnum.Buy
serializer.Serialize(writer, "buy")
Return
Case TypeEnum.Sell
serializer.Serialize(writer, "sell")
Return
End Select
Throw New Exception("Cannot marshal type TypeEnum")
End Sub
Public Shared ReadOnly Singleton As TypeEnumConverter = New TypeEnumConverter()
End Class
End Namespace
Then install Newtonsoft (if not already) and Imports it
Then Imports HotBit (or if you changed the Namespace of the "paste this" above, Imports that new namespace
Then do your request and query the result e.g.:
Sub Main(args As String())
Dim s = New WebClient().DownloadString("https://api.hotbit.io/api/v1/market.deals?market=KIBA/USDT&limit=150&last_id=1521100930&api_key=44812d8f-66d3-01c0-94c3b29305040b03&sign=98EEC3D69D3F70F9BDFED901984B2AA4")
Dim tc = TradeCollection.FromJson(s)
Dim prices = String.Join(","c, tc.Result.Select(Function(r) r.Price))
End Sub

Newtonsoft JSON parsing into object

My VB is a bit rusty but I need to parse a JSON string. I did it already in C# where I didn't have an issue. This is an old project and I'm using VS2008 for it.
This is my class:
Public Class ResponseMeta
Private _type As String
<JsonProperty("type")> _
Public Property type() As String
Get
Return _type.ToString()
End Get
Set(ByVal value As String)
_type = value
End Set
End Property
Private _message As String
<JsonProperty("message")> _
Public Property message() As String
Get
Return _message
End Get
Set(ByVal value As String)
_message = value
End Set
End Property
Private _message_v1 As String
<JsonProperty("message-v1")> _
Public Property message_v1() As String
Get
Return _message_v1
End Get
Set(ByVal value As String)
_message_v1 = value
End Set
End Property
Private _message_v2 As String
<JsonProperty("message-v2")> _
Public Property message_v2() As String
Get
Return _message_v2
End Get
Set(ByVal value As String)
_message_v2 = value
End Set
End Property
Private _message_v3 As String
<JsonProperty("message-v3")> _
Public Property message_v3() As String
Get
Return _message_v3
End Get
Set(ByVal value As String)
_message_v3 = value
End Set
End Property
Private _message_v4 As String
<JsonProperty("message-v4")> _
Public Property message_v4() As String
Get
Return _message_v4
End Get
Set(ByVal value As String)
_message_v4 = value
End Set
End Property
End Class
The code to deserialize is:
Dim test As String
test = "{""response-meta"":{""type"":""S"",""message"":"""",""Total No Of Records"":"""",""message-v1"":""1"",""message-v2"":"""",""message-v3"":"""",""message-v4"":""""}}"
Dim testcl As ResponseMeta
testcl = JsonConvert.DeserializeObject(Of ResponseMeta)(test)
All properties of the object are set to Nothing and if I add watch, it says:
type = {"Object reference not set to an instance of an object."}
I have now spent countless hours on this and Google doesn't found a hint or a clue of what might be getting wrong here.
Any suggestions are very welcome.
The JSON does not match up to what you are trying to parse it to.
You are missing a root object.
Public Class RootObject
Private _root As ResponseMeta
<JsonProperty("response-meta")> _
Public Property ResponseMeta() As ResponseMeta
Get
Return _root
End Get
Set(ByVal value As ResponseMeta)
_root = value
End Set
End Property
End Class
So based on the JSON you would need to deserialize to root object first then get the meta data
Dim root As RootObject = JsonConvert.DeserializeObject(Of RootObject)(test)
Dim testcl As ResponseMeta = root.ResponseMeta

Writing and Reading JSON in VB.net using Newtonsoft

This is my first time using JSON and I'm stuck. I'm trying to send a test SMS via http://sms.roamtech.com/smsapi/. The format is:
Send message format(json).
{
"result":{
"account":"xxxx",
"user":"xxxx",
"password":"xxxxxxxx",
"requestType":"BULK",
"alphanumeric":"xxxxxxxx",
"data":{
"linkid":"xxxxxxx",
"msisdn":"xxxxxxxxxxx",
"networkid":"1",
"message":"xxxxxxxxxxxx",
"callback":"http//test"
}
}
}
So, this is what I've come up with after reviewing various posts on this and other sites:
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports System.IO
Imports System.Net
Imports System.Text
Module modJSON
Public Class clsResult
Public account As String
Public user As String
Public password As String
Public requestType As String
Public alphanumeric As String
Public data As New clsData
End Class
Public Class clsData
Public linkid As String
Public msisdn As String
Public networkid As String
Public message As String
Public callback As String
End Class
Public Class clsPOST
Public result As New clsResult
End Class
Public Sub chkJSON()
Dim r As New clsResult
Dim d As New clsData
Dim x As New clsPOST
r.account = "8852"
r.user = "username"
r.password = "password"
r.requestType = "BULK"
r.alphanumeric = "SMSLEO"
d.linkid = "1001"
d.msisdn = "2547xxxxxxxx"
d.networkid = "1"
d.message = "Just a test"
d.callback = "http://infiniti-africa.com/json"
r.data = d
x.result = r
Dim uriRoam As New Uri("http://sms.roamtech.com/smsapi")
Dim strJSON = JsonConvert.SerializeObject(x, Formatting.Indented)
Dim bytJSON = Encoding.UTF8.GetBytes(strJSON)
Dim result_post = SendRequest(uriRoam, bytJSON, "application/json", "POST")
MsgBox(result_post)
End Sub
Private Function SendRequest(uri As Uri, jsonDataBytes As Byte(), contentType As String, method As String) As String
Dim req As WebRequest = WebRequest.Create(uri)
req.ContentType = contentType
req.Method = method
req.ContentLength = jsonDataBytes.Length
Dim stream = req.GetRequestStream()
stream.Write(jsonDataBytes, 0, jsonDataBytes.Length)
stream.Close()
Dim response = req.GetResponse().GetResponseStream()
Dim reader As New StreamReader(response)
Dim res = reader.ReadToEnd()
reader.Close()
response.Close()
Return res
End Function
End Module
The string strJSONseems to contain the correct key:value combinations. However, the code doesn't send the test SMS and I don't get any response. 'SendRequest' returns an empty string.
Also, I'm not sure what to use for the "callback" url, which is where the delivery report is forwarded.
Note:
1. "linkid" is a unique message ID
2. "msidn" is the recipient phone number
Any help is appreciated.
I have also tried using the following class:
Public Class JsonPost
Private urlToPost As String = ""
Public Sub New(ByVal urlToPost As String)
Me.urlToPost = urlToPost
End Sub
Public Function postData(pstData As Byte()) As Boolean
Dim webClient As New WebClient()
Dim resByte As Byte()
Dim resString As String
Try
webClient.Headers("content-type") = "application/json"
resByte = webClient.UploadData(Me.urlToPost, "post", pstData)
resString = Encoding.Default.GetString(resByte)
Console.WriteLine(resString)
webClient.Dispose()
Return True
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Return False
End Function
End Class
Then calling:
Dim strJSON = JsonConvert.SerializeObject(x)
Dim bytJSON = Encoding.UTF8.GetBytes(strJSON)
Dim jsonPost As New JsonPost("http://sms.roamtech.com/smsapi")
jsonPost.postData(bytJSON)
I'm still getting nothing. Been struggling with this for three days now. Any ideas anyone?
Turns out I've been stressing for four days over a trailing slash (/). The API URL is:
http://sms.roamtech.com/smsapi/
While I've been using:
http://sms.roamtech.com/smsapi
Lesson learnt.

WebService Asp.Net Json not serialize a List(Of Class)

after a lot of time searching here and in the web, i'm posting my problem and my code for yours teach me how i do this works.
The problem is that the Json not serialize listUsuarios, when i use JavaScriptSerializer the return is "{}" and when i use JsonConvert.SerializeObject the return is "False".
Sorry for my bad english.
Here is the code...
USUARIOS.VB
Imports Microsoft.VisualBasic
Public Class Usuarios
Private _Codigo As Long
Private _Nome As String
Private _Telefone As String
Public Property Codigo As Integer
Get
Return _Codigo
End Get
Set(ByVal value As Integer)
_Codigo = value
End Set
End Property
Public Property Nome() As String
Get
Return _Nome
End Get
Set(ByVal value As String)
_Nome = value
End Set
End Property
Public Property Telefone() As String
Get
Return _Telefone
End Get
Set(ByVal value As String)
_Telefone = value
End Set
End Property
End Class
Public Class ListUsuarios
Private listUsuarios As List(Of Usuarios)
Public Sub New()
listUsuarios = New List(Of Usuarios)
End Sub
Public Sub AddItem(ByVal usuario As Usuarios)
listUsuarios.Add(usuario)
End Sub
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
Public Function Item(ByVal Index As Integer) As Usuarios
Return CType(listUsuarios.Item(Index), Usuarios)
End Function
Public Function Count() As Integer
Return listUsuarios.Count
End Function
End Class
ANDROID.VB
Imports Newtonsoft.Json
Imports System.Configuration
Imports System.Data
Imports System.Data.OleDb
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class Android
Inherits System.Web.Services.WebService
Dim Dt As DataTable
Dim Da As New OleDbDataAdapter
Dim Cmd As New OleDbCommand
Dim cn As New OleDb.OleDbConnection
<WebMethod()> _
Public Function Android(query As String) As String
Dim listUsuario As ListUsuarios = carregaDadosAccess(query)
Return retornaDadosJSON(listUsuario)
End Function
Private Function getConexaoDB() As OleDbConnection
Try
cn.ConnectionString = ConfigurationManager.ConnectionStrings("MyLocalAccess").ConnectionString
cn.Open()
Return cn
Catch ex As Exception
Throw ex
End Try
End Function
Private Sub closeConexaoDB(ByVal cn As OleDbConnection)
Try
If cn.State = ConnectionState.Open Then
cn.Close()
End If
Catch ex As Exception
Throw ex
End Try
End Sub
Private Function carregaDadosAccess(selectCommmand As String) As ListUsuarios
Dim usuario As Usuarios = Nothing
Dim listUsuario As New ListUsuarios
Dim i As Long = 0
Try
cn = getConexaoDB()
Dim da As New OleDb.OleDbDataAdapter(selectCommmand, cn)
Dim dt As New DataTable
Dim arrImage() As Byte = Nothing
Dim myMS As New IO.MemoryStream
da.Fill(dt)
If dt.Rows.Count > 0 Then
Do
usuario = New Usuarios
usuario.Codigo = dt.Rows(i).Item("key-codigo")
usuario.Nome = dt.Rows(i).Item("dad-descri")
usuario.Telefone = dt.Rows(i).Item("dad-telefo")
listUsuario.AddItem(usuario)
i = i + 1
If i = dt.Rows.Count Then Exit Do
Loop
Else
listUsuario = Nothing
End If
Catch ex As Exception
Throw ex
Finally
closeConexaoDB(cn)
End Try
Return listUsuario
End Function
Private Function retornaDadosJSON(listUsuario As ListUsuarios) As String
'Json serializer do prĂ³prio .net
'Dim JsonSerializer As New JavaScriptSerializer
'Return JsonSerializer.Serialize(listUsuario)
'Json serializer James Newton-King
Dim JsonSerializer As String = ""
Return JsonSerializer = JsonConvert.SerializeObject(listUsuario)
End Function
End Class
The first problem is you are returning a value that compares an empty string with the serialized json string and since the json serialized string is not empty. This is where the result of "False" is coming from.
You can fix that problem by changing the method to:
Private Function retornaDadosJSON(listUsuario As ListUsuarios) As String
Return JsonConvert.SerializeObject(listUsuario)
End Function
You can prevent this type of issue in the future by adding the following directives to the top of each file:
Option Explicit On
Option Strict On
or by setting the corresponding values in the project's Compile property page (you can also set these to default values for new projects in Visual Studio's Tools > Options > Projects and Solutions > VB Default).
Option Strict On would have prevented that code from compiling. It would also show you that there is a data type difference between _Codigo and Codigo (one is Long the other is Integer).
The second problem is that ListUsuarios isn't defined well for what you are trying to do with it. It would be much better to inherit from List(Of Usuarios) than your current design.
Changing to the following class will both reduce the code and ensure the data is serialized correctly:
Public Class ListUsuarios
Inherits List(Of Usuarios)
Public Sub AddItem(ByVal usuario As Usuarios)
Me.Add(usuario)
End Sub
End Class

save x,y spectrum data in table in ms-access

I want to create a table for LEDs. This table creates information such as name, center wavelength and the spectrum, which itself is data in the format intensity over wavelenth as 2 x n table data.
I am a beginner in access and have currently no clue how to insert this to a table.
I could of course create for each LED a table on its own, but there will be hundreds of these spectrum datas.
Such a complex data structure may be difficult to implement in a database table. An option I propose is to have a set of classes that represent the data. Then you can serialize and deserialize (read and write) the data to a file.
Sample Implementation
Module Module1
Sub Main()
Dim leds = New List(Of LED)()
Dim rnd = New Random()
'create a bunch of LEDs
For i = 1 To 10
Dim led = New LED("LED " & (i + 1).ToString(), rnd.Next(0, i * 100))
For x = 1 To 10
led.Spectrum.Add(New SpectrumInfo(rnd.Next(1, 10), rnd.Next(1000, 10000)))
Next
leds.Add(led)
Next
' write the led data to a file
Using sw As New IO.StreamWriter("LED Data.ledx")
Dim xs = New System.Xml.Serialization.XmlSerializer(leds.GetType())
xs.Serialize(sw, leds)
End Using
'read the led data from a file
Dim leds2 = New List(Of LED)()
Using sr = New System.IO.StreamReader("LED Data.ledx")
Dim xs = New System.Xml.Serialization.XmlSerializer(leds2.GetType())
leds2 = DirectCast(xs.Deserialize(sr), List(Of LED))
End Using
'confirm the two are the same
Console.WriteLine("LEDs and LEDS2 are " & If(leds.SequenceEqual(leds2), "the same", "different"))
' alternate saving using binary serializer
' works in cases where XmlSerializer doesn't
' produces smaller files too
'save the led data
Using fs = New System.IO.FileStream("LED Data.ledb", IO.FileMode.Create)
Dim bf = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
bf.Serialize(fs, leds)
End Using
'read the led data
Dim leds3 = New List(Of LED)()
Using fs = New System.IO.FileStream("LED Data.ledb", IO.FileMode.Open)
Dim bf = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
leds3 = DirectCast(bf.Deserialize(fs), List(Of LED))
End Using
'confirm equality
Console.WriteLine("LEDs and LEDS3 are " & If(leds.SequenceEqual(leds3), "the same", "different"))
Console.WriteLine("LEDs2 and LEDS3 are " & If(leds2.SequenceEqual(leds3), "the same", "different"))
Console.ReadLine()
End Sub
End Module
<Serializable()> _
Public Class LED
Dim _name As String
Dim _cWL As Double
Dim _spectrum As List(Of SpectrumInfo)
Public Sub New()
_name = String.Empty
_cWL = 0
_spectrum = New List(Of SpectrumInfo)()
End Sub
Public Sub New(name As String, cwl As Double, ParamArray spectrum() As SpectrumInfo)
_name = name
_cWL = cwl
_spectrum = New List(Of SpectrumInfo)(spectrum)
End Sub
Public Property Name As String
Get
Return _name
End Get
Set(value As String)
_name = value
End Set
End Property
Public Property CenterWavelength As Double
Get
Return _cWL
End Get
Set(value As Double)
_cWL = value
End Set
End Property
Public ReadOnly Property Spectrum As List(Of SpectrumInfo)
Get
Return _spectrum
End Get
End Property
Public Overrides Function Equals(obj As Object) As Boolean
If Not (TypeOf obj Is LED) Then Return False
Dim l2 = DirectCast(obj, LED)
Return l2._name = _name AndAlso l2._cWL = _cWL AndAlso l2._spectrum.SequenceEqual(_spectrum)
End Function
Public Overrides Function ToString() As String
Return String.Format("{0} [{1}]", _name, _cWL)
End Function
Public Overrides Function GetHashCode() As Integer
Dim result As Integer
For Each spec In _spectrum
result = result Xor spec.GetHashCode()
Next
Return result Xor (_name.GetHashCode() + _cWL.GetHashCode())
End Function
End Class
<Serializable()> _
Public Structure SpectrumInfo
Dim _intensity As Double
Dim _wavelength As Double
Public Sub New(intensity As Double, wavelength As Double)
_intensity = intensity
_wavelength = wavelength
End Sub
Public ReadOnly Property Intensity As Double
Get
Return _intensity
End Get
End Property
Public ReadOnly Property Wavelength As Double
Get
Return _wavelength
End Get
End Property
Public Overrides Function Equals(obj As Object) As Boolean
If TypeOf obj Is SpectrumInfo Then
Dim si = DirectCast(obj, SpectrumInfo)
Return si._wavelength = _wavelength AndAlso si._intensity = _intensity
Else
Return False
End If
End Function
Public Overrides Function ToString() As String
Return String.Format("Intensity: {0}, Wavelength: {1}", _intensity, _wavelength)
End Function
Public Overrides Function GetHashCode() As Integer
Return _intensity.GetHashCode() Xor _wavelength.GetHashCode()
End Function
End Structure
You might look at http://r937.com/relational.html
I think you want:
LED Table
ID
LEDName
CenterWavelength
And then a table for spectra
ID
LedId
Intensisty
WaveLength