Results 1 to 2 of 2

Thread: images from Database

  1. #1
    HernandezOrtiz is offline Senior Member
    Join Date
    Dec 2009
    Posts
    301
    Rep Power
    3

    Default images from Database

    Inserting and retrieving images from Database

    How to load and insert the images into database using code in ASP.NET and I am using SQL Server as a backend. I am not able to loading and calling an image from database.

    I have called the data from database and passed to string. Any help would be highly appreciated.

  2. #2
    MartinWilson is offline Senior Member
    Join Date
    Dec 2009
    Posts
    281
    Rep Power
    3

    Default

    If you would like to call the data from database and you are using front end as a .net and back end as a SQL Server .Absolutely, you can do this and I do not think any problem should be come.

    C#.net code:

    private void button2_Click(object sender, EventArgs e)

    {
    const string conString = "Data Source=apex2006sql;Initial Catalog=ServManLeather;Integrated Security=True;";

    const string firequery = "Select ImgNumber, FacilityImg From FacilityImg Where ImgNumber = 1000";

    using (SqlConnection sqlconn = new SqlConnection(conString))

    {

    sqlconn.Open();
    using (SqlCommand comnd = new SqlCommand(firequery, sqlconn))

    {

    using (SqlDataReader rdr = comnd.ExecuteReader())

    {

    using (DataTable tbdata = new DataTable())

    {

    tbdata.Load(rdr);
    File.WriteAllBytes(@"C:\picture.bmp", (byte[])dt.Rows[0]["FacilityImg"]);

    }

    }

    }

    }

    }

    Vb.net Code:

    Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs)
    Const conString As String = "Data Source=apex2006sql;Initial Catalog=ServManLeather;Integrated Security=True;"
    Const firequery As String = "Select ImgNumber, FacilityImg From FacilityImg Where ImgNumber = 1000"
    Using sqlconn As New SqlConnection(conString)
    sqlconn.Open()
    Using comnd As New SqlCommand(firequery, sqlconn)
    Using rdr As SqlDataReader = comnd.ExecuteReader()
    Using tbdata As New DataTable()
    tbdata.Load(rdr)
    File.WriteAllBytes("C:\picture.bmp", DirectCast(dt.Rows(0)("FacilityImg"), Byte()))
    End Using
    End Using
    End Using
    End Using
    End Sub

Similar Threads

  1. Database .NET
    By Izaiah Lopez in forum Download Tools and Softwares
    Replies: 0
    Last Post: 10-20-2010, 06:54 PM
  2. Database Normalization in SQL Database
    By Millerjames in forum Programming
    Replies: 1
    Last Post: 01-23-2010, 03:17 PM
  3. Database
    By adlina in forum Everything Else
    Replies: 0
    Last Post: 03-23-2009, 11:21 AM
  4. Database
    By MACONAQUEA77 in forum Everything Else
    Replies: 0
    Last Post: 03-21-2009, 09:51 AM
  5. Database
    By techno23 in forum Everything Else
    Replies: 0
    Last Post: 03-27-2008, 09:43 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48