When i updating record then this error is coming...please guide
below mentioned behind update button code
- int id = int.Parse(lbid.Text);
- string filePath = FileUpload1.PostedFile.FileName;
- string customername = txtcus.Text;
- string filename = Path.GetFileName(filePath);
- string ext = Path.GetExtension(filename);
- string contenttype = String.Empty;
- switch (ext) {
- case ".doc":
- contenttype = "application/vnd.ms-word";
- break;
- case ".docx":
- contenttype = "application/vnd.ms-word";
- break;
- case ".xls":
- contenttype = "application/vnd.ms-excel";
- break;
- case ".xlsx":
- contenttype = "application/vnd.ms-excel";
- break;
- case ".jpg":
- contenttype = "image/jpg";
- break;
- case ".png":
- contenttype = "image/png";
- break;
- case ".gif":
- contenttype = "image/gif";
- break;
- case ".pdf":
- contenttype = "application/pdf";
- break;
- }
- Stream fs = FileUpload1.PostedFile.InputStream;
- BinaryReader br = new BinaryReader(fs);
- Byte[] bytes = br.ReadBytes((Int32) fs.Length);
-
-
- string query = "UPDATE Customer SET ";
- SqlCommand cmd = new SqlCommand(query, con);
- if (!string.IsNullOrEmpty(customername)) {
- query += "CustomerName =@CustomerName,";
- cmd.Parameters.AddWithValue("@CustomerName", customername);
- }
- if (!string.IsNullOrEmpty(filename)) {
- query += "Name = @Name,";
- cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = filename;
- }
- if (bytes.Length > 0) {
- query += "Data=@Data,";
- cmd.Parameters.Add("@Data", SqlDbType.Binary).Value = bytes;
- }
- if (!string.IsNullOrEmpty(contenttype)) {
- query += "ContentType=@ContentType,";
- cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value = contenttype;
- }
- query = query.TrimEnd(',');
- query += " WHERE CustomerId =@Id";
- cmd.Parameters.AddWithValue("@Id", id);
- con.Open();
- cmd.ExecuteNonQuery();
- con.Close();