Click here to Skip to main content
15,908,437 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello I need some help with this ?
I am working with a project with google maps. i need help to populate the 'var all[];(*see code.) from a dataset(mysql db) codebehind.
Javascript code:

C#
var all =[

               ["Location 1", "Summerdale Rd", "Elon", "NC", "27253", "36.150491", "-79.5470544","1"],
                ["Location 2", "7205 Olmstead Dr", "Burlington", "NC", "27215", "36.069974", "-79.548101","2"],
            ];



            var infoWindow = new google.maps.InfoWindow;
            map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
            // Set the center of the map
            var pos = new google.maps.LatLng(59.3697329, 17.9746453);
            map.setCenter(pos);
              // marker.setIcon('nostarch-logo.png', [27,31]);
            function infoCallback(infowindow, marker) {
                return function() {
                infowindow.open(map, marker);
                map.setZoom(17);
                map.panTo(marker.position);

            };
       }
       function setMarkers(map, all) {
        for (var i in all) {

                  var name  = all[i][0];
                var address = all[i][1];
                var city    = all[i][2];
                var state   = all[i][3];
                var zip     = all[i][4];
                var lat     = all[i][5];
                var lng     = all[i][6];
                var typ     = all[i][7];
                var latlngset;

            latlngset = new google.maps.LatLng(lat, lng);
              var marker = new google.maps.Marker({
                  map: map,  title: name,  position: latlngset , icon: 'p2.png'
                  });


Code behind:
VB
Dim db, driver As String
        db = "marker"
        driver = "{MySQL ODBC 5.1 Driver}"



        Dim strConn As String = "DRIVER=" & driver & ";SERVER=localhost;DATABASE=" & db & ";" & _
"USER=root;PASSWORD=; OPTION=3;"
        Dim MySQL As String = "select * from marks "
        Dim MyConn As New OdbcConnection(strConn)
        Dim ds As Data.DataSet = New DataSet()
        Dim Cmd As New OdbcDataAdapter(MySQL, MyConn)
        'MyConn.Open()

        Cmd.Fill(ds, "ID")

        For I = 0 To _
               ds.Tables("ID").Rows.Count - 1

              ** code to populate javascript *all



        Next


        MyConn.Close()
Posted

1 solution

Convert DataSet or XML to JSON using VB.NET[^]

Take a look at and play with your results. Alternatively you could just build the string and send that to the browser.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900