How to insert coordinates on Javascript Api to table...???

715
0
12-20-2010 07:15 AM
DanielTuracek
New Contributor
I will really appreciate if anybody can help me with this problem...
Im working under Visual Studio for VisualBasic asp.net web aplication.
I working on a tool which take a Coordinates from map image in JAVASCRIPT API a insert them in Oracle table.
I found code in samples which return coordinates from image and I know how to insert another  values(for example from string) to table. But i really freezing on solution how to get it everything together.
I cannot export variable (coordinate) from javascript  to VBscript(or directly to sql string). I found many answers thats not possible to do that on this way.
So my question is how to do that?
Is better to get everything under VBscript? or Is there any trick which i still dont seeing?


This is code for Default.aspx.vb

[HTML]
Imports System
Imports System.Data
Imports Oracle.DataAccess.Client
Partial Public Class _Default
    Inherits System.Web.UI.Page
    'I need get coordinates for these two public variables(there are values just only for showing,thats code works)
    Public S As String = "5"
    Public D As String = "2"

    Dim con As OracleConnection = New OracleConnection()
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        con.ConnectionString = "User Id=sde;Password=esprit;Data Source=TURACEK2/ORCL;"
        ''''''''''''''''
        '2. Open database connection through ODP.NET:
        ''''''''''''''''
        Try
            ' Open the connection
            con.Open()
            Debug.Print("DATabase connected!")

        Catch ex As Exception

            Debug.Print(ex.Message)

        End Try
        ''''''''''''''''

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        '3. Create command object to perform a query against the database:
        ''''''''''''''''
        'SURADNICE is my table
        Dim cmdQuery As String = "INSERT INTO SURADNICE (X, Y)VALUES(" & S & ", " & D & ")"

        ' Create the OracleCommand object
        Dim cmd As OracleCommand = New OracleCommand(cmdQuery)
        cmd.Connection = con
        cmd.CommandType = CommandType.Text
        ''''''''''''''''
        '4. Fetch data into an OracleDataReader object and display the data. Then, close the connection object:
        ''''''''''''''''
        Try
            ' Execute command, create OracleDataReader object
            Dim reader As OracleDataReader = cmd.ExecuteReader()
            While (reader.Read())

                ' Output Employee Name and Number
                Debug.Print("Employee Number : " & _
                                  reader.GetDecimal(0) & _
                                                 " , " & _
                                    "Employee Name : " & _
                reader.GetString(1))

            End While
            Debug.Print("Values were added")
        Catch ex As Exception

            Debug.Print(ex.Message)

        Finally

            ' Dispose OracleCommand object
            cmd.Dispose()

            ' Close and Dispose OracleConnection object
            con.Close()
            con.Dispose()

        End Try
    End Sub
End Class
[/HTML]

and this is code for Default.aspx

[HTML]<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="Javascript_samotne_pripojenie2._Default" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="Oracle.DataAccess.Client" %>
<%  Dim MyServerSideVariable As String = ""%>
<%  Dim MyServerSideVariable2 As String = ""%>
   
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >


<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7" />
  <title>Project a point</title>

  <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css">
  <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6" type="text/javascript"></script>

  <script type="text/javascript">
     
      dojo.require("esri.map");
      dojo.require("esri.tasks.geometry");
     
     
      var map = null;
      var gsvc = null;
      var pt = null;

      function initialize() {
          map = new esri.Map("map");
          var layer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
          map.addLayer(layer);
          map.setExtent(new esri.geometry.Extent(-144.13584773952124, 7.981485927970198, -52.76454682003924, 68.8956865409582, new esri.SpatialReference({ wkid: 4326 })));

          gsvc = new esri.tasks.GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
          dojo.connect(map, "onClick", projectToWebMercator);
      }

      function projectToWebMercator(evt) {
          map.graphics.clear();
          var point = evt.mapPoint;
          var symbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_DIAMOND);
          var graphic = new esri.Graphic(point, symbol);
          var outSR = new esri.SpatialReference({ wkid: 102113 });
          map.graphics.add(graphic);

          gsvc.project([graphic], outSR, function(features) {
              pt = features[0].geometry;
                     var MyClientSideVariable = pt.x;
                   var MyClientSideVariable2 = pt.y;
              graphic.setInfoTemplate(new esri.InfoTemplate("Coordinates",
          "<p> X: " + MyClientSideVariable +
          "<br/> Y: " + MyClientSideVariable2 +
          "</p>"));
              map.infoWindow
          .setTitle(graphic.getTitle())
          .setContent(graphic.getContent())
          .show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));

          });

      }

      dojo.addOnLoad(initialize);
  </script>
</head>

<body class="tundra">
  <b>Click a location on the map to Project from LatLng -> Web Mercator:</b>
 
  <div id="map" style="width:600px; height:400px; border:1px solid #000";></div>

<input type="hidden" name="S" value="MyClientSideVariable">
<input type="hidden" name="V" value="MyClientSideVariable2">
    add data:
    <form id="form1" runat="server" onclick="return form1_onclick()">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" />

    </div>
    </form>
   
</body>
</html>
[/HTML]
0 Kudos
0 Replies