Hi rani,
Using the below article i have created the example.
Check this example. Now please take its reference and correct your code.
Database
For this example i am making use of a table named tblFiles whose schema is defined as follows.
You can download the database table SQL by clicking the download link below.
Download SQL file
HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('MyApp', [])
app.controller('MyController', function ($scope, $http, $interval) {
$http.post("Default.aspx/GetImages", { headers: { 'Content-Type': 'application/json'} })
.then(function (response) {
$scope.Images = response.data.d;
});
$scope.Image = null;
var index = 0;
$interval(function () {
$scope.Image = $scope.Images[index];
$scope.$apply();
index++;
if (index > $scope.Images.length - 1) {
index = 0
}
}, 1000);
});
</script>
<div ng-app="MyApp" ng-controller="MyController" style="text-align: center">
<img ng-src="{{'data:image/png;base64,' + Image.Data}}" ng-show="Image.Data" />
<br />
<span>{{Image.Name}}</span>
</div>
Namespaces
C#
using System.Configuration;
using System.Data.SqlClient;
using System.Web.Services;
VB.Net
Imports System.Configuration
Imports System.Data.SqlClient
Imports System.Web.Services
Code
C#
[WebMethod]
public static List<object> GetImages()
{
List<object> files = new List<object>();
string sql = "SELECT id,Name,Data FROM tblFiles";
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlCommand cmd = new SqlCommand(sql))
{
cmd.Connection = conn;
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
files.Add(new
{
Id = sdr["id"].ToString(),
Name = sdr["Name"].ToString(),
Data = Convert.ToBase64String((byte[])sdr["Data"])
});
}
}
conn.Close();
}
return files;
}
}
VB.Net
<WebMethod()>
Public Shared Function GetImages() As List(Of Object)
Dim files As List(Of Object) = New List(Of Object)()
Dim sql As String = "SELECT id,Name,Data FROM tblFiles"
Using conn As SqlConnection = New SqlConnection()
conn.ConnectionString = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using cmd As SqlCommand = New SqlCommand(sql)
cmd.Connection = conn
conn.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
files.Add(New With {
.Id = sdr("id").ToString(),
.Name = sdr("Name").ToString(),
.Data = Convert.ToBase64String(CType(sdr("Data"), Byte()))
})
End While
End Using
conn.Close()
End Using
Return files
End Using
End Function
Screenshot