Click here to Skip to main content
15,881,812 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: regarding MDI forms Pin
Rupesh Kumar Swami22-Sep-08 0:09
Rupesh Kumar Swami22-Sep-08 0:09 
AnswerRe: regarding MDI forms Pin
pdnet22-Sep-08 0:16
pdnet22-Sep-08 0:16 
AnswerRe: regarding MDI forms Pin
Dave Kreskowiak22-Sep-08 8:44
mveDave Kreskowiak22-Sep-08 8:44 
GeneralRe: regarding MDI forms Pin
marygoldg22-Sep-08 19:55
marygoldg22-Sep-08 19:55 
GeneralRe: regarding MDI forms Pin
Dave Kreskowiak23-Sep-08 1:55
mveDave Kreskowiak23-Sep-08 1:55 
QuestionSaving & Retrieving An Image Pin
Member 367504721-Sep-08 23:00
Member 367504721-Sep-08 23:00 
AnswerRe: Saving & Retrieving An Image Pin
jzonthemtn22-Sep-08 2:08
jzonthemtn22-Sep-08 2:08 
AnswerRe: Saving & Retrieving An Image Pin
Rupesh Kumar Swami22-Sep-08 3:05
Rupesh Kumar Swami22-Sep-08 3:05 
hi,
follow step by step
1. first of all i assume PictureBox1 hold the picture data. So use following statement

Dim PictureBox1Data As Byte()<br />
        If PictureBox1.Image Is Nothing Then<br />
            PictureBox1Data = Nothing<br />
        Else<br />
            PictureBox1Data = imageToByteArray(PictureBox1.Image)'See below this function<br />
        End If


2.Now write the SQL query as following
Dim QueryText As String<br />
        Dim QueryValue As String<br />
        Dim command As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand()<br />
QueryText = "INSERT INTO Settings(PrintCompany,IsUploadLogo,LogoGraphic )"<br />
            QueryValue = "Values(@PrintCompany, @IsUploadLogo,@LogoGraphic)" <br />
            command.CommandText = QueryText & QueryValue<br />

3. Supply Value to parameter which is in above query, as following

command.Parameters.Add("@PrintCompany", SqlDbType.TinyInt, 10).Value = True<br />
        command.Parameters.Add("@IsUploadLogo", SqlDbType.TinyInt, 10).Value =True<br />
If Not PictureBox1Data Is Nothing Then<br />
            command.Parameters.Add("@LogoGraphic", SqlDbType.Image, PictureBox1Data.Length).Value = PictureBox1Data<br />
        Else<br />
            command.Parameters.Add("@LogoGraphic", SqlDbType.Image, 0).Value = System.DBNull.Value<br />
        End If


4. Execute query as following
command.ExecuteNonQuery()

step 1 to 4 read data of picture box,convert them byte array and store in related table.Step 1 use following function to convert an image into byte array

Public Function imageToByteArray(ByVal ImageIn As System.Drawing.Image) As Byte()<br />
       Dim ms As MemoryStream = New MemoryStream()<br />
       Dim FormatImage1 As Imaging.ImageFormat = ImageIn.RawFormat<br />
       ImageIn.Save(ms, FormatImage1)<br />
       'ImageIn.Save(ms, Imaging.ImageFormat.Bmp)<br />
       Return ms.ToArray()<br />
   End Function


5. Now Use following statement to get dataset
str = "select * from Settings"<br />
        Dim ds As New DataSet<br />
        ds = mdIns.GetResultFromQuery(str)'this function return dataset<br />


6. use dataset record as following

If ds.Tables(0).Rows.Count > 0 Then<br />
             chkPrintCompanyName.Checked = CBool(ds.Tables(0).Rows(0).Item(0))<br />
            chkLogoGraphic.Checked = CBool(ds.Tables(0).Rows(0).Item(1))<br />
            If Not IsDBNull(ds.Tables(0).Rows(0).Item(4)) And Not ds.Tables(0).Rows(0).Item(2) Is Nothing Then<br />
                PictureBox1.Image = ByteArrayToimage(ds.Tables(0).Rows(0).Item(2))<br />
            End If<br />
            <br />
        End If


step 6 use following function for convert Byte array to Image

Public Function ByteArrayToimage(ByVal ImageArray As Byte()) As Image<br />
       Dim ms As MemoryStream = New MemoryStream(ImageArray)<br />
       Dim ReturnImage As Image = Image.FromStream(ms)<br />
       Return ReturnImage<br />
   End Function


hope this helps

Rupesh Kumar Swami
Software Developer,
Integrated Solution,
Bikaner (India)

My Company
Award: Best VB.NET article of June 2008: Create Column Charts Using OWC11

GeneralRe: Saving & Retrieving An Image Pin
EngrImad6-Nov-21 11:12
EngrImad6-Nov-21 11:12 
QuestionRunning a project from a mapped network drive Pin
Hazelrah21-Sep-08 21:02
Hazelrah21-Sep-08 21:02 
AnswerRe: Running a project from a mapped network drive Pin
Johan Hakkesteegt21-Sep-08 21:51
Johan Hakkesteegt21-Sep-08 21:51 
GeneralRe: Running a project from a mapped network drive Pin
Hazelrah23-Sep-08 17:03
Hazelrah23-Sep-08 17:03 
QuestionExport sqldata to a notepad and import data from notepad to sql Pin
AnieMVC21-Sep-08 20:29
AnieMVC21-Sep-08 20:29 
AnswerRe: Export sqldata to a notepad and import data from notepad to sql Pin
Ashfield21-Sep-08 21:42
Ashfield21-Sep-08 21:42 
AnswerRe: Export sqldata to a notepad and import data from notepad to sql Pin
Johan Hakkesteegt21-Sep-08 21:53
Johan Hakkesteegt21-Sep-08 21:53 
QuestionEmail Attachment Pin
mighty_mouse21-Sep-08 18:40
mighty_mouse21-Sep-08 18:40 
RantRe: Email Attachment Pin
Zaegra21-Sep-08 19:27
Zaegra21-Sep-08 19:27 
AnswerRe: Email Attachment Pin
Ashfield21-Sep-08 21:43
Ashfield21-Sep-08 21:43 
AnswerRe: Email Attachment Pin
Smithers-Jones21-Sep-08 22:54
Smithers-Jones21-Sep-08 22:54 
GeneralRe: Email Attachment Pin
Thomas Stockwell22-Sep-08 6:15
professionalThomas Stockwell22-Sep-08 6:15 
GeneralRe: Email Attachment Pin
Smithers-Jones22-Sep-08 22:05
Smithers-Jones22-Sep-08 22:05 
AnswerRe: Email Attachment Pin
Steven J Jowett22-Sep-08 11:53
Steven J Jowett22-Sep-08 11:53 
QuestionImage Encryption and Decrypting Pin
sarfarazaliqureshi21-Sep-08 9:53
sarfarazaliqureshi21-Sep-08 9:53 
AnswerRe: Image Encryption and Decrypting Pin
jzonthemtn21-Sep-08 13:06
jzonthemtn21-Sep-08 13:06 
GeneralRe: Image Encryption and Decrypting Pin
sarfarazaliqureshi22-Sep-08 8:03
sarfarazaliqureshi22-Sep-08 8:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.