1

Hey all I am trying to return my data to a datatable.net table. I am looking at the example they give HERE. The data comes back looking like so when viewing Chrome debug console:

0: "["111","1/30/2016 12:00:00 AM","10:00 a.m.-2:00 p.m. ","College ","5600 Road, Suite E3 ","37987","33.0090696,-81.21471799999999","theTown","TN","Hamilton ","","blank","1/14/2015 12:00:00 AM","Blank","10/22/2015 10:00:57 AM"],
    ["110","1/29/2016 12:00:00 AM","12:30 p.m.-7:00 p.m. ","College ","5600 Road, Suite E3 ","37045","31.0090696,-80.21471799999999","theTown","TN","Hamilton ","","blank","1/13/2015 12:00:00 AM","Blank","10/22/2015 10:00:57 AM"],
    ["109","1/28/2016 12:00:00 AM","12:30 p.m.-7:00 p.m. ","College ","5600 Road, Suite E3 ","37899","32.0090696,-87.21471799999999","theTown","TN","Hamilton ","","blank","1/12/2015 12:00:00 AM","Blank","10/22/2015 10:00:57 AM"],
    ["108","1/27/2016 12:00:00 AM","12:30 p.m.-7:00 p.m. ","College ","5600 Road, Suite E3 ","37411","22.0090696,-84.2240999999","theTown","TN","Hamilton ","","blank","1/11/2015 12:00:00 AM","Blank","10/22/2015 10:00:57 AM"],
    etc etc...."

enter image description here The JS I am using is this:

$.ajax({
   url: 'default.aspx?Data=viewData&cache=' + nocache,
   dataType: 'text',
   type: 'GET',
   success: function (dataSet) {
        var dataT = [dataSet];
        console.log(dataT);
        $('#databaseName').html('<strong>Data </strong> for <strong>FEB</strong> Form <strong>' + dbName + '</strong></h3>');
        $('#theDataTable').DataTable({
            data: dataT,
            columns: [
                 { title: "Venue ID" },
                 { title: "Venue Date" },
                 { title: "Venue Time" },
                 { title: "Venue Name" },
                 { title: "Venue Address" },
                 { title: "Venue Zip" },
                 { title: "Venue Address" },
                 { title: "Venue Lat/Lng" },
                 { title: "Venue City" },
                 { title: "Venue State" },
                 { title: "Venue County" },
                 { title: "Venue Advocate" },
                 { title: "in Spanish?" },
                 { title: "Last Updated" },
                 { title: "Updated By" }
            ]
        });
   }
});

And the output on the page looks like this:

enter image description here

What am I doing incorrectly and how can I go about fixing it so that the data lines up correctly?

Server side code:

Dim _tmpHtml As String = Nothing

theQuery = "SELECT * " & _
           "FROM markers " & _
           "ORDER BY venueID DESC;"

sqlQ = New SqlCommand(theQuery, conn)
reader = sqlQ.ExecuteReader

If reader.HasRows Then
   While reader.Read()
       _tmpHtml += "["
       _tmpHtml += """" & EscapeLikeValue(reader("venueID").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("venueEventDate").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("venueTime").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("venueName").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("venueAddress").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("venueZip").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("venueLatLong").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("venueCity").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("venueState").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("venueCounty").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("venueAdvocate").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("venueSpanish").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("lastUpdated").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("updatedBy").ToString()) & ""","
       _tmpHtml += """" & EscapeLikeValue(reader("syssrcloaddt").ToString()) & """"
       _tmpHtml += "],"
       records += 1
   End While

   _tmpHtml = _tmpHtml.Trim().Remove(_tmpHtml.Length - 1)

   reader.Close()
   sqlQ = Nothing
   conn.Close()
   conn = Nothing

   'Dim serializer As New JavaScriptSerializer()
   'Dim jsonString As String = serializer.Serialize(_tmpHtml)

   Return _tmpHtml
Else
   .......
End If
StealthRT
  • 10,108
  • 40
  • 183
  • 342
  • Your response may not be a valid JSON, hard to say. Show how you generate the response on the server. – Gyrocode.com Nov 12 '15 at 20:05
  • 1
    @Gyrocode.com updated the OP to show that code for you, – StealthRT Nov 12 '15 at 21:02
  • You should stop generating JSON manually, there are many ways to do it automatically, see [this](http://stackoverflow.com/a/16166658/3549014). Once you return a valid JSON which should be an array of arrays, use `data: dataSet` as jQuery DataTables initialization option. – Gyrocode.com Nov 12 '15 at 21:12
  • @Gyrocode.com Would you mind sharing an answer with some code to show your correction to my issue? I don't think using serialization json in my vb code would format it correctly as it would be expected? – StealthRT Nov 12 '15 at 21:18

1 Answers1

0

I do not know what you are doing . but can this helpful for you , you can do like this can you put your json code in 2 textbox of vb. and loop through the value and add each item .

val1 = "textbox1.txt" & + &"loopvalue" & + &" textbox2.txt"
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
TOM
  • 873
  • 1
  • 12
  • 35