使用Javascript(C#)从Mysql数据库中检索数据 [英] Retrieve Data from Mysql Database using Javascript (C#)

查看:81
本文介绍了使用Javascript(C#)从Mysql数据库中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

P / S:请帮助,我想连接我的数据库,但没有工作。任何人都可以帮助我。 TQ



 



 <   html     xmlns   =  http://www.w3.org/1999/ xhtml >  
< head >
< title > < / title >
< script type = text / jav ascript src = http://maps.googleapis.com/maps/api/js?sensor=false > < / script >
< script language = javascript 类型 = text / javascript >

//从Mysql DB
var map中选择坐标;
var geocoder;
var marker;
函数InitializeMap(){

var latlng = new google.maps.LatLng(,);
var myOptions =
{
zoom:17,
center:latlng,
mapTypeId:google.maps.MapTypeId.ROADMAP,
disableDefaultUI:true
};
map = new google.maps.Map(document.getElementById(map),myOptions);
marker = new google.maps.Marker({position:new google.maps.LatLng(,),map:map});
}

window.onload = InitializeMap;

< / script >
< / head >
< body 样式 = height: 500px >
< >
< tr >
< / tr >
< tr >
< td colspan = 2 >
< div id = map style = height:529px;宽度:100%; margin-top:0px; >
< / div >
< < span class =code-leadattribute> / td >
< / tr >
< / table >
< ; / body >
< / html >







 使用系统; 
< span class =code-keyword>我们ing System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 MySql.Data.MySqlClient;

public partial class Creating_a_Simple_Map:System.Web.UI.Page
{
public static string 纬度;
public static string 经度;
MySqlDataReader dr;

受保护 void Page_Load( object sender,EventArgs e)
{
using (MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection( Server = localhost; Database = db; Uid = ****; Pwd = ****))
{
connection.Open();
MySqlCommand cmd = connection.CreateCommand();
cmd.CommandText = SELECT纬度,经度FROM信号;

dr = cmd.ExecuteReader();

while (dr.Read())
{
latitude = dr [ 0 ]的ToString();
longitude = dr [ 1 ]。ToString();
}
connection.Close();
}

Response.Write( < script type ='text / javascript'src ='http://maps.googleapis.com/maps/api/js?sensor = false'>< / script>);
Response.Write( < script language ='javascript'type ='text / javascript'>
+ var map;
+ var marker;
+ function InitializeMap(){
+ var latlng = new google.maps.LatLng( + latitude + +经度+ );
+ var myOptions =
+ {zoom:17,center:latlng,mapTypeId:google.maps.MapTypeId.ROADMAP,disableDefaultUI: true};
+ map = new google.maps.Map(document.getElementById ('map'),myOptions);
+ marker = new google.maps .Marker({position:new google.maps.LatLng( + latitude + + longitude + ),map:map}); }
+ window.onload = InitializeMap;
+ < / script>);
}
}

解决方案

使用页面方法并从javascript连接到数据库..


P/S : Please help, i want to connect with my database but didn't work. Anyone can help me. TQ


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script language="javascript" type="text/javascript">

        //select coordinates from Mysql DB
        var map;
        var geocoder;
        var marker;
        function InitializeMap() {

            var latlng = new google.maps.LatLng("", "");
            var myOptions =
            {
                zoom: 17,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                disableDefaultUI: true
            };
            map = new google.maps.Map(document.getElementById("map"), myOptions);
            marker = new google.maps.Marker({ position: new google.maps.LatLng("", ""), map: map });
        }

        window.onload = InitializeMap;

    </script>
</head>
<body style="height: 500px">
    <table>
        <tr>
        </tr>
        <tr>
            <td colspan="2">
                <div id="map" style="height: 529px; width: 100%; margin-top: 0px;">
                </div>
            </td>
        </tr>
    </table>
</body>
</html>




using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;

public partial class Creating_a_Simple_Map : System.Web.UI.Page
{
    public static string latitude;
    public static string longitude;
    MySqlDataReader dr;

    protected void Page_Load(object sender, EventArgs e)
    {
        using (MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection("Server=localhost;Database=db;Uid=****;Pwd=****"))
        {
            connection.Open();
            MySqlCommand cmd = connection.CreateCommand();
            cmd.CommandText = "SELECT latitude,longitude FROM signal";

            dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                latitude = dr[0].ToString();
                longitude = dr[1].ToString();
            }
            connection.Close();
        }

        Response.Write("<script type='text/javascript' src='http://maps.googleapis.com/maps/api/js?sensor=false'></script>");
        Response.Write("<script language='javascript' type='text/javascript'>"
        + "var map;"
        + "var marker;"
        + "function InitializeMap() {"
        + "var latlng = new google.maps.LatLng(" + latitude + "," + longitude + ");"
        + "var myOptions ="
        + "{ zoom: 17, center: latlng,mapTypeId: google.maps.MapTypeId.ROADMAP,disableDefaultUI: true};"
        + "map = new google.maps.Map(document.getElementById('map'), myOptions);"
        + "marker = new google.maps.Marker({ position: new google.maps.LatLng(" + latitude + ", " + longitude + "), map: map }); }"
        + "window.onload = InitializeMap;"
        + "</script>");
    }
}

解决方案

use page methods and connect to data base from javascript..


这篇关于使用Javascript(C#)从Mysql数据库中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆