Jyoti Jodha

Jyoti Jodha

  • NA
  • 1.7k
  • 406.9k

The variable name '@logo' has already been declared. c#

Sep 6 2017 3:05 AM
The variable name '@logo' has already been declared. Variable names must be unique within a query batch or stored procedure. in  windows form c#
  1. cmd = new SqlCommand("insert into cmpny_dtl(c_name,adrs,c_phone,,logo ,state_id ) values(@c_name,@adrs,@c_phone,@state_id )", con);  
  2. con.Open();  
  3. cmd.Parameters.AddWithValue("@c_name", CmpnyName_txt.Text);  
  4. cmd.Parameters.AddWithValue("@adrs", Adrs_txt.Text);  
  5. cmd.Parameters.AddWithValue("@c_phone", CmpnyPhone_txt.Text);  
  6. cmd.Parameters.AddWithValue("@logo""@logo");  
  7. cmd.Parameters.AddWithValue("@state_id", STATE_comboBox.SelectedValue);  
  8. if (pictureBox1.Image != null)  
  9. {  
  10. MemoryStream ms = new MemoryStream();  
  11. pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);  
  12. byte[] photo = ms.ToArray();  
  13. cmd.Parameters.AddWithValue("@logo", photo);  
  14. }  
  15. else  
  16. {  
  17. cmd.Parameters.AddWithValue("@logo", (pictureBox1.Image == null) ? (object)DBNull.Value : pictureBox1.Image).SqlDbType = SqlDbType.Image;  
  18. }  
  19. int k = cmd.ExecuteNonQuery();  
  20. cmd.ExecuteNonQuery();  
  21. con.Close();  
  22. MessageBox.Show("Record Inserted Successfully");   

Answers (3)