Hi
Please refer below sample.
HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<img id="imgData" alt="" width="100" height="100" />
<script type="text/javascript">
$(function () {
$.ajax({
type: "POST",
url: "Default.aspx/GetPath",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
$('#imgData').attr('src', response.d)
},
failure: function (response) {
alert(response.responseText);
},
error: function (response) {
alert(response.responseText);
}
});
});
</script>
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Services;
VB.Net
Imports System.Data.SqlClient
Imports System.Web.Services
Imports System.Configuration
Code
C#
[WebMethod]
public static string GetPath()
{
string path = string.Empty;
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string query = "SELECT TOP 1 Filepath FROM tblfiles";
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
con.Open();
path = Convert.ToString(cmd.ExecuteScalar());
con.Close();
}
}
return path;
}
VB.Net
<WebMethod>
Public Shared Function GetPath() As String
Dim path As String = String.Empty
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim query As String = "SELECT TOP 1 Filepath FROM tblfiles"
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand(query, con)
con.Open()
path = Convert.ToString(cmd.ExecuteScalar())
con.Close()
End Using
End Using
Return path
End Function
Screenshot