Hey ArunaAbi,
Please refer below sample.
Namespaces
C#
using System.Data.SqlClient;
VB.Net
Imports System.Data.SqlClient
Code
C#
private void Form1_Load(object sender, EventArgs e)
{
string constr = @"Server=.\SQL2005;DataBase=dbFiles;UID=sa;PWD=pass@123";
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT TOP 1 Name FROM tblFilesPath", con))
{
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
da.Fill(dt);
string file = Application.StartupPath.Replace("bin\\Debug", "") + @"Image\" + dt.Rows[0]["Name"];
pictureBox1.Image = new Bitmap(file);
}
}
}
}
VB.Net
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim constr As String = "Server=.\SQL2005;DataBase=dbFiles;UID=sa;PWD=pass@123"
Using con As SqlConnection = New SqlConnection(constr)
Using cmd As SqlCommand = New SqlCommand("SELECT TOP 1 Name FROM tblFilesPath", con)
Using da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim dt As DataTable = New DataTable()
da.Fill(dt)
Dim file As String = Application.StartupPath.Replace("bin\Debug", "") & "Image\" + dt.Rows(0)("Name")
pictureBox1.Image = New Bitmap(file)
End Using
End Using
End Using
End Sub
Screenshot
