从数据集c#或vb填充javascript数组 [英] populate javascript array from dataset c# or vb
本文介绍了从数据集c#或vb填充javascript数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我需要一些帮助吗?
我正在使用谷歌地图的项目。我需要帮助从数据集(mysql db)代码隐藏中填充'var all [];(*参见代码。)。
Javascript代码:
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:
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:
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()
推荐答案
使用VB.NET将DataSet或XML转换为JSON [ ^ ]
看看和玩你的结果。或者,您可以构建字符串并将其发送到浏览器。
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.
这篇关于从数据集c#或vb填充javascript数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文