Hi jilSoft,
Please refer below sample.
Database
I am making use of a table named Files whose schema is defined as follows.
For insert you can refer below article.
You can download the database table SQL by clicking the download link below.
Download SQL file
HTML
<div>
<asp:ScriptManager runat="server" EnablePageMethods="true" />
<img id="imgData" alt="Images" width="100" height="100" />
</div>
<script type="text/javascript">
window.onload = function () {
PageMethods.GetPath(function (response) {
document.getElementById("imgData").src = response;
});
}
</script>
Namespaces
C#
using System.Data.SqlClient;
using System.Web.Services;
using System.Configuration;
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 Path FROM Files";
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 Path FROM Files"
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