Hi akhter,
Check this example. Now please take its reference and correct your code.
HTML
Home
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
<asp:Button ID="btnDetails" runat="server" Text="Details" OnClick="btnDetails_Click" />
Default
<asp:TextBox ID="txtName" runat="server" ReadOnly="true"></asp:TextBox>
<br /><br />
<asp:Image ID="Image1" runat="server" />
Namespaces
C#
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Code
C#
Home
protected void btnDetails_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx?ID=" + this.txtID.Text);
}
Default
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
if (Request.QueryString["ID"] != "")
{
string strcon = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(strcon))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT Name,Data FROM [dbFiles].[dbo].[tblFiles] WHERE id = @Id";
cmd.Parameters.AddWithValue("@Id", Request.QueryString["ID"]);
con.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
txtName.Text = sdr["Name"].ToString();
byte[] bytes = (byte[])sdr["Data"];
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
Image1.ImageUrl = "data:image/png;base64," + base64String;
}
con.Close();
}
}
}
}
}
VB.Net
Home
Protected Sub btnDetails_Click(sender As Object, e As System.EventArgs)
Response.Redirect("Default.aspx?ID=" + Me.txtID.Text)
End Sub
Default
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
If Request.QueryString("ID") <> "" Then
Dim strcon As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(strcon)
Using cmd As SqlCommand = New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT Name,Data FROM [dbFiles].[dbo].[tblFiles] WHERE id = @Id"
cmd.Parameters.AddWithValue("@Id", Request.QueryString("ID"))
con.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
If sdr.Read() Then
txtName.Text = sdr("Name").ToString()
Dim bytes As Byte() = CType(sdr("Data"), Byte())
Dim base64String As String = Convert.ToBase64String(bytes, 0, bytes.Length)
Image1.ImageUrl = "data:image/png;base64," & base64String
End If
con.Close()
End Using
End Using
End If
End If
End Sub
Screenshot