Getting error while inserting values into database (SQL Server 2008)
Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query.
Code:
da.InsertCommand = new SqlCommand("insert into tblProductMaster ([Name],[Type],[Height],[Width],[Length],[Price]) values( @Name , @Type , @Height , @Width , @Length , @Price )", con);
da.InsertCommand.Parameters.Add("@Name", SqlDbType.VarChar).Value = txtName.Text;
da.InsertCommand.Parameters.Add("@Type", SqlDbType.VarChar, 10).Value = Convert.ToString(ddlType.SelectedItem);
da.InsertCommand.Parameters.Add("@Height", SqlDbType.Float).Value = float.Parse(txtHeight.Text);
da.InsertCommand.Parameters.Add("@Width", SqlDbType.Float).Value = float.Parse(txtWidth.Text);
da.InsertCommand.Parameters.Add("@Length", SqlDbType.Float).Value = float.Parse(txtLength.Text);
da.InsertCommand.Parameters.Add("@Price", SqlDbType.SmallMoney).Value = int.Parse(txtPrice.Text);
da.InsertCommand.ExecuteNonQuery();