Server Error in '/' Application.
String or binary data would be truncated.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.
Source Error:
Line 59: cmd.Connection = con;
Line 60: con.Open();
Line 61: cmd.ExecuteNonQuery();
Line 62: con.Close();
Line 63: // this.GetData();
code
protected void btnsubmit5_Click(object sender, EventArgs e)
{
string strname = ""; // ADDED
if (FileUploadImage.HasFile)
{
strname = FileUploadImage.FileName.ToString();
FileUploadImage.PostedFile.SaveAs(Server.MapPath("~/UserImage/") + strname); // string imagename = FileUpload1.PostedFile.FileName;
// FileUpload1.SaveAs(Server.MapPath("~/UserImage/" + imagename));
// string fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName());
SqlConnection con = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand("INSERT INTO Employees (Name,Address,Phone,Gender,Location,Department,State,Salary,Images) VALUES(@Name,@Address,@Phone,@Gender,@Location,@Department,@State,@Salary,@Images)", con);
// cmd.Parameters.AddWithValue("@UserName", HttpContext.Current.Session["userName"]);
cmd.Parameters.AddWithValue("@Name", txtname.Text.Trim());
cmd.Parameters.AddWithValue("@Address", txtaddress.Text.Trim());
cmd.Parameters.AddWithValue("@Phone", txtphone.Text.Trim());
cmd.Parameters.AddWithValue("@Gender", ddlgender.SelectedItem.Text.Trim());
cmd.Parameters.AddWithValue("@Location", txtlocation.Text.Trim());
cmd.Parameters.AddWithValue("@Department", ddldepartment.SelectedItem.Text.Trim());
cmd.Parameters.AddWithValue("@Images", strname);
cmd.Parameters.AddWithValue("@State", txtstate.Text.Trim());
cmd.Parameters.AddWithValue("@Salary", txtsalary.Text.Trim());
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
// this.GetData();
}
}