Vipin
Vipin

Reputation: 261

String or binary data would be truncated. The statement has been terminated?8

I am trying to save image file on db in binary format. I am using data set to write insert query. As a beginner I don't know how to use these things. While using the given below code get some errors. They are: String or binary data would be truncated. The statement has been terminated

Please help me.

Code:

 protected void btnSubmit_Click(object sender, EventArgs e)
    {
        DataSet1TableAdapters.Tbl_EmpTableAdapter adp1;
        adp1 = new DataSet1TableAdapters.Tbl_EmpTableAdapter();
        adp1.GetInsert(txtEmpName.Text,FileUpload1);
    }

Source:

<asp:TextBox ID="txtEmpName" runat="server"></asp:TextBox> &#10038</td>
 <asp:FileUpload ID="FileUpload1" runat="server" />
 <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />

Insert Query:

INSERT INTO Tbl_Emp (EmpName, EmpPic) VALUES (@EmpName,@EmpPic)

Data base:

enter image description here

Upvotes: 0

Views: 856

Answers (1)

CodeCaster
CodeCaster

Reputation: 151594

Try storing FileUpload.FileBytes instead of the entire upload control.

And to prevent your next question: please change the column type to varbinary(max) to be able to store files larger than 50 bytes.

Upvotes: 3

Related Questions