如何将p标记中的内容保存到SQL Server?

时间:2019-04-19 03:29:20

标签: sql-server html5

我想将<p>标记内的内容存储到数据库中。有可能吗?

<p align="center">
<button type="submit" class="btn btn-success" id="btnCheckin" onclick="getLocation()">Check In</button>
<button type="submit" class="btn btn-success" id="btnCheckout" onclick="getLocation()">Check Out</button>
</p>
<p id="demo"></p>

<script type="text/javascript">
    var x = document.getElementById("demo");

    function getLocation() {
      if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
      } else { 
        x.innerHTML = "Geolocation is not supported by this browser.";
      }
    }

    function showPosition(position) {
      x.innerHTML = "Latitude: " + position.coords.latitude + 
      "<br>Longitude: " + position.coords.longitude;
    }

</script>

以下是我尝试过的内容。但是在带有红色下划线的演示中,我出现了错误。

protected void btnCheckin_Click(object sender, EventArgs e)
{
    string mainconn = ConfigurationManager.ConnectionStrings["Myconnection"].ConnectionString;

    SqlConnection sqlconn = new SqlConnection(mainconn);

    string sqlQuery = "INSERT INTO Locate (Locate_LongLat) VALUES @Locate_LongLat";

    SqlCommand sqlcomm = new SqlCommand(sqlQuery, sqlconn);
    sqlcomm.Parameters.AddWithValue("@Locate_LongLat", demo);

    sqlconn.Open();
    sqlcomm.ExecuteNonQuery();
}

是否可以将p标签的内容存储到数据库中?如果不能,如何存储经度和纬度值?

0 个答案:

没有答案