none
I have the following code and I am looking to insert the image file to my sql database that has been unploaded to azure storage. RRS feed

  • Question

  • Private Async Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
    
            Try
                ToolStripStatusLabel1.Text = "Uploading"
                Await Task.Delay(txtDelay.Text)
    
                Dim AZBlob As New AzureBlob(ConfigurationManager.AppSettings(StorageConnectionString), mycontainer)
    
                Await AZBlob.UploadAsync(PictureBox1.ImageLocation, cancelToken)
    
    
                '---Insert in SQL Table using PictureBox1.ImageLocation
    my table has the columns:
    Id
    FileUrl
    FileData
    OriginalName
    ContentType
    DateCreated
    
    
    
    
    
    
               ToolStripStatusLabel1.Text = ""
                PictureBox1.Image = Nothing
            Catch exCancel As OperationCanceledException
                Dim message As String = "upload canceled at Form"
                MessageBox.Show(message)
                ToolStripStatusLabel1.Text = message
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                ToolStripStatusLabel1.Text = ex.Message
            End Try
        End Sub

    Wednesday, January 22, 2020 3:23 PM

Answers

  • Hi eruig, 

    Thank you for posting here.

    For Azure SQL Database, you need to define correct connection string.

    You can refer to the following code to insert data into Azure SQL Database.

            Dim cnString = "Server=tcp:xxx.database.windows.net,1433;Initial Catalog=xxx;Persist Security Info=False;User ID=xxx;Password=xxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
            Dim cmdText As String = "insert into yourTable
                       (Id,FileUrl,FileData,OriginalName,ContentType,DateCreated)
                       values(@Id, @FileUrl,@FileData,@OriginalName,@ContentType,@DateCreated)"
            Using con As SqlConnection = New SqlConnection(cnString)
                Using cmd As SqlCommand = New SqlCommand(cmdText, con)
                    con.Open()
                    cmd.Parameters.AddWithValue("@Id", "your Id")
                    cmd.Parameters.AddWithValue("@FileUrl", "your FileUrl")
                    cmd.Parameters.AddWithValue("@FileData", "your FileData")
                    cmd.Parameters.AddWithValue("@OriginalName", "your OriginalName")
                    cmd.Parameters.AddWithValue("@ContentType", "your ContentType")
                    cmd.Parameters.AddWithValue("@DateCreated", "your DateCreated")
                    cmd.ExecuteNonQuery()
                    con.Close()
                End Using
            End Using
    

    Hope it could be helpful.

    Best Regards,

    Xingyu Zhao



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by eruig Friday, January 24, 2020 3:19 PM
    Thursday, January 23, 2020 2:35 AM
    Moderator

All replies

  • Hi eruig, 

    Thank you for posting here.

    For Azure SQL Database, you need to define correct connection string.

    You can refer to the following code to insert data into Azure SQL Database.

            Dim cnString = "Server=tcp:xxx.database.windows.net,1433;Initial Catalog=xxx;Persist Security Info=False;User ID=xxx;Password=xxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
            Dim cmdText As String = "insert into yourTable
                       (Id,FileUrl,FileData,OriginalName,ContentType,DateCreated)
                       values(@Id, @FileUrl,@FileData,@OriginalName,@ContentType,@DateCreated)"
            Using con As SqlConnection = New SqlConnection(cnString)
                Using cmd As SqlCommand = New SqlCommand(cmdText, con)
                    con.Open()
                    cmd.Parameters.AddWithValue("@Id", "your Id")
                    cmd.Parameters.AddWithValue("@FileUrl", "your FileUrl")
                    cmd.Parameters.AddWithValue("@FileData", "your FileData")
                    cmd.Parameters.AddWithValue("@OriginalName", "your OriginalName")
                    cmd.Parameters.AddWithValue("@ContentType", "your ContentType")
                    cmd.Parameters.AddWithValue("@DateCreated", "your DateCreated")
                    cmd.ExecuteNonQuery()
                    con.Close()
                End Using
            End Using
    

    Hope it could be helpful.

    Best Regards,

    Xingyu Zhao



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by eruig Friday, January 24, 2020 3:19 PM
    Thursday, January 23, 2020 2:35 AM
    Moderator
  • Thank you

    Friday, January 24, 2020 3:19 PM