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 constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
- //SqlConnection con = new SqlConnection(constr);
- 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();


Priyanka JainRank #356 · 7K reputationPosted Aug 28, 2019, 10:09 PM EDT
Sonu GuptaRank #1,261 · 1.4K reputationPosted Aug 28, 2019, 10:34 PM EDT
Amit GuptaRank #190 · 12.8K reputationPosted Aug 28, 2019, 7:21 AM EDT
Jaish MathewsRank #225 · 11K reputationPosted Aug 28, 2019, 7:33 AM EDT
Amit GuptaRank #190 · 12.8K reputationPosted Aug 28, 2019, 8:31 AM EDT
Akhter HUssainRank #1,521 · 1K reputationPosted Aug 28, 2019, 7:34 AM EDT
Akhter HUssainRank #1,521 · 1K reputationPosted Aug 28, 2019, 8:01 AM EDT
Akhter HUssainRank #1,521 · 1K reputationPosted Aug 28, 2019, 8:46 AM EDT
Priyanka JainRank #356 · 7K reputationPosted Aug 28, 2019, 8:53 AM EDT
Sonu GuptaRank #1,261 · 1.4K reputationPosted Aug 28, 2019, 7:37 PM EDT
Akhter HUssainRank #1,521 · 1K reputationPosted Aug 28, 2019, 8:14 PM EDT