Currently I'm developing a student portal with an appropriate and simple login system for my college's final year project purpose. This is one of the command button (to save photo to SQL server) I've encountered error. This is the error statement:

> 
> System.Data.SqlClient.SqlException: 'String or binary data would be truncated.
>  The statement has been terminated.'
> 
> 
> 

```vb
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
    'String imagelocation = ""

    Dim images() As Byte = Nothing
    'Dim imagelocation As String
    'imagelocation = ""
    Dim Stream As New FileStream(imagelocation, FileMode.Open, FileAccess.Read)
    Dim brs As New BinaryReader(Stream)
    images = brs.ReadBytes(CInt(Stream.Length))

    Dim source As String = "Data Source=LAPTOP-85ALBAVS\SQLEXPRESS;Initial Catalog=Portal;Integrated Security=True"
    Dim con As New SqlConnection(source)
    con.Open()

    Dim cmd As String = "Insert into Photo Values('" + TextBox2.Text + "', @images)"

    Dim qry As New SqlCommand(cmd, con)
    qry.Parameters.Add(New SqlParameter("@images", images))

    'qry.Parameters.Add(new SqlParameter("@images", pictureBox1));
    ***Dim i As Integer = qry.ExecuteNonQuery()

    If i >= 1 Then
        MessageBox.Show("Successfull!", "message", MessageBoxButtons.OK)
    Else
        MessageBox.Show("Fail!", "message", MessageBoxButtons.OK)
    End If
 End Sub
End Class

```

This is a SQL table for me to save the uploaded photo into database. Any help would be appreciated. Thanks.

![Table](https://i.stack.imgur.com/y15fa.jpg)

**UPDATE**

Previously`Photo`column name changed to`Img`, `Photo`would be the table name.

So I tried to switch the code into another method which is:

```vb
    Dim source As String = "Data Source=LAPTOP-85ALBAVS\SQLEXPRESS;Initial Catalog=Portal;Integrated Security=True"
    Dim con As New SqlConnection(source)
    Dim command As New SqlCommand("Insert into Photo (Img, Pname) Values (@Img, @Pname)", con)
    Dim ms As New MemoryStream
    pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat)

    command.Parameters.Add("@Img", SqlDbType.Image).Value = ms.ToArray()
    command.Parameters.Add("@Pname", SqlDbType.VarChar).Value = TextBox2.Text
    con.Open()

    If command.ExecuteNonQuery() = 1 Then
        MessageBox.Show("Successfully uploaded", "Message", MessageBoxButtons.OK)
    Else
        MessageBox.Show("Failed. Try again.", "Message", MessageBoxButtons.OK)
    End If

```

So it's actually worked I guess. Not sure if there would be any hidden error. Any comment would be helpful guys. This is the output of `Photo` table.
[`Photo`table output](https://i.stack.imgur.com/gkB7r.jpg)