Dear all,
I'm saving an image into an MyExpress SQL database in the following way:
Then I'm trying to recall it into another form with the following code:Code:Dim cmdSchiera As SqlCommand Dim insertSchiera As String = String.Empty Dim dbsourceSchiera As String = ConfigurationManager.ConnectionStrings("CTO_Management_ConnectionString").ConnectionString Dim connSchiera = New SqlConnection(dbsourceSchiera) cmdSchiera = New SqlCommand cmdSchiera.Connection = connSchiera connSchiera.Open() insertSchiera = "INSERT INTO Tbl_CTOSchieramento (Codice_partita, Schieramento) VALUES(@CodParSchiera,@Pitch)" cmdSchiera.CommandType = CommandType.Text cmdSchiera.CommandText = insertSchiera cmdSchiera.Parameters.Clear() Dim codiceSchiera As String = "" codiceSchiera = TxtPSquadraC.Text.Trim + TxtPSquadraT.Text.Trim + CmbPLeva.Text.Trim + TxtPNOsservatore.Text.Trim + TxtPCOsservatore.Text.Trim + DtPckrPDatapartita.Value.ToShortDateString cmdSchiera.Parameters.Add("@CodParSchiera", SqlDbType.NChar).Value = codiceP Dim ms As New MemoryStream() PctSchieramento.Image.Save(ms, Imaging.ImageFormat.Jpeg) Dim data As Byte() = ms.GetBuffer() Dim p As New SqlParameter("@Pitch", SqlDbType.Image) p.Value = data cmdSchiera.Parameters.Add(p) cmdSchiera.ExecuteNonQuery() connSchiera.Close()
Now, the image is properly retrieved according to the selection parameters, it is shown, but not in a stretch mode - it is enlarged and then shelled.Code:cmdSchiera.CommandText = "SELECT Schieramento FROM Tbl_CTOSchieramento WHERE Codice_partita = @CodParSP" cmdSchiera.Parameters.Add("@CodParSP", SqlDbType.NChar).Value = codicepartitaDettagli cmdSchiera.Connection = New SqlConnection(connSPstring) cmdSchiera.Connection.Open() Dim dataSchieraGP As New System.Data.DataTable Dim adapterSchiera As New SqlDataAdapter adapterSchiera = New SqlDataAdapter(cmdSchiera) Dim commandSchiera As New SqlCommandBuilder(adapterSchiera) adapterSchiera.Fill(dataSchieraGP) If dataSchieraGP.Rows.Count > 0 Then Dim picbyteSchiera() As Byte = dataSchieraGP.Rows(0).Item("Schieramento") Dim picSchiera As New System.IO.MemoryStream(picbyteSchiera) PartiteDataDisplay.PctDPSchiera.BackgroundImage = Image.FromStream(picSchiera) PartiteDataDisplay.PctDPSchiera.BackgroundImageLayout = ImageLayout.Stretch End If adapterSchiera.Dispose() cmdSchiera.Dispose() cmdSchiera.Connection.Close()
How can I fix it? Please consider also that the two pictureboxes - the one from which the picture is saved and the second one in which it is supposed to be shown - have the same size.
Thanks,
A.




Reply With Quote
