Getting error:Operand type clash: nvarchar is incompatible with image

Waqas

I have image field in tblEmployee for employee's picture.

When i am trying to save employee's detail without image file in uploader it threw and error

"Operand type clash: nvarchar is incompatible with image"

while when i select any picture from dialog box then it works fine. I am using c# windows applications.

My Code looks like as:

byte[] bimage=null;
           if(txtPic.Text!="")
            {
               string  image=txtPic.Text;
                Bitmap bmp=new Bitmap(image);
                FileStream fs=new FileStream(image,FileMode.Open,FileAccess.Read);
                bimage=new byte[fs.Length];
                fs.Read(bimage,0,Convert.ToInt32(fs.Length));
                fs.Close();
            }
                cmd = new SqlCommand("sp_insert_new_employee",conn);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@name",txtName.Text.Trim());
                cmd.Parameters.AddWithValue("@fname",txtFName.Text.Trim());
                cmd.Parameters.AddWithValue("@dob",Convert.ToDateTime(dtDOB.Text));
                cmd.Parameters.AddWithValue("@nic",txtCNIC.Text.Trim());
                cmd.Parameters.AddWithValue("@add",txtAdd.Text.Trim());
                cmd.Parameters.AddWithValue("@emptype",cmbEmpType.SelectedItem.ToString());
                if(bimage!=null)
                  cmd.Parameters.AddWithValue("@imgdata", SqlDbType.Image).Value = bimage;
                else
                    cmd.Parameters.AddWithValue("@imgdata", SqlDbType.Image).Value = DBNull.Value;
                cmd.Parameters.AddWithValue("@descr",txtDescr.Text.Trim());
                conn.Open();
                cmd.ExecuteNonQuery();
                conn.Close();
                MessageBox.Show("Successfully added....!");`

Any one have any idea where am i making mistake?

Spider man

Usually we get this error while passing DBNull.Value as the value. Can you try the following.

instead of

cmd.Parameters.AddWithValue("@imgdata", SqlDbType.Image).Value = DBNull.Value;

use the following.

SqlParameter imageParameter = new SqlParameter("@imgdata", SqlDbType.Image);
imageParameter .Value = DBNull.Value;
cmd.Parameters.Add(imageParameter );

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Operand type clash: nvarchar is incompatible with Type_WP_Days

From Dev

Operand type clash: nvarchar is incompatible with Type_WP_Days

From Dev

Operand type clash: text is incompatible with uniqueidentifier

From Dev

Operand type clash: text is incompatible with uniqueidentifier

From Dev

Operand type clash: bigint is incompatible with time

From Dev

Operand type clash geography is incompatible with float

From Dev

Operand type clash: date is incompatible with int in dateadd

From Dev

Tsql Operand type clash: date is incompatible with int

From Dev

Sql Server Operand type clash: date is incompatible with int

From Dev

Sql Server Operand type clash: date is incompatible with int

From Dev

c# Operand type clash: date is incompatible with int

From Dev

Stored Procedure Operand type clash: date is incompatible with int

From Dev

NHibernate component mapping: Operand type clash: bigint is incompatible with time

From Dev

Table type parameter in a stored procedure cause operand type clash error

From Dev

Operand data type nvarchar is invalid for subtract operator

From Dev

getting error unsupported operand type(s) for +: 'int' and 'str'

From Dev

Splash Image naming clash and PNG crush error

From Dev

Error: "Improper operand type"

From Dev

Type error: unsupported operand

From Dev

incompatible type C error?

From Dev

Greenfoot incompatible type error

From Dev

Operand Data Type Clash when executing sp_help_job via VB.Net

From Dev

Python Type Error Unsupported Operand

From Dev

Error: operand types are incompatible ("int" and "const char*") c++

From Dev

GCD Queue Incompatible Type Error

From Dev

incompatible type error facebook flow

From Dev

Getting "warning:assignment from incompatible pointer type"

From Dev

Why I am getting `incompatible types error`?

From Dev

Unsupported operand type(s) for +: 'float' and 'str' error

Related Related

  1. 1

    Operand type clash: nvarchar is incompatible with Type_WP_Days

  2. 2

    Operand type clash: nvarchar is incompatible with Type_WP_Days

  3. 3

    Operand type clash: text is incompatible with uniqueidentifier

  4. 4

    Operand type clash: text is incompatible with uniqueidentifier

  5. 5

    Operand type clash: bigint is incompatible with time

  6. 6

    Operand type clash geography is incompatible with float

  7. 7

    Operand type clash: date is incompatible with int in dateadd

  8. 8

    Tsql Operand type clash: date is incompatible with int

  9. 9

    Sql Server Operand type clash: date is incompatible with int

  10. 10

    Sql Server Operand type clash: date is incompatible with int

  11. 11

    c# Operand type clash: date is incompatible with int

  12. 12

    Stored Procedure Operand type clash: date is incompatible with int

  13. 13

    NHibernate component mapping: Operand type clash: bigint is incompatible with time

  14. 14

    Table type parameter in a stored procedure cause operand type clash error

  15. 15

    Operand data type nvarchar is invalid for subtract operator

  16. 16

    getting error unsupported operand type(s) for +: 'int' and 'str'

  17. 17

    Splash Image naming clash and PNG crush error

  18. 18

    Error: "Improper operand type"

  19. 19

    Type error: unsupported operand

  20. 20

    incompatible type C error?

  21. 21

    Greenfoot incompatible type error

  22. 22

    Operand Data Type Clash when executing sp_help_job via VB.Net

  23. 23

    Python Type Error Unsupported Operand

  24. 24

    Error: operand types are incompatible ("int" and "const char*") c++

  25. 25

    GCD Queue Incompatible Type Error

  26. 26

    incompatible type error facebook flow

  27. 27

    Getting "warning:assignment from incompatible pointer type"

  28. 28

    Why I am getting `incompatible types error`?

  29. 29

    Unsupported operand type(s) for +: 'float' and 'str' error

HotTag

Archive