This stored procedure does not save the data, it seems to be a problem with the VARBINARY
. I am passing a byte[]
to it, but then it doesn't work. If I send this parameter as NULL
it works.
I'm calling the procedure with the following code:
public Community AddCommunity(string name, string description, byte[] picture, User owner, int? venue, int communityID)
{
using (var database = new Database())
{
return database.Scope.GetSqlQuery<Community>("QP_AddCommunity ?, ?, ?, ?, ?, ?", "VARCHAR Name, VARCHAR Description, VARBINARY Picture, INTEGER Owner, INTEGER Venue, INTEGER ID").GetResult(name, description, picture, owner.ID, venue, communityID);
}
}
The procedure is the following:
CREATE PROCEDURE [dbo].[QP_AddCommunity]
@Name VARCHAR(120),
@Description VARCHAR(MAX),
@Picture VARBINARY(MAX),
@Owner INTEGER,
@Venue INTEGER,
@ID INTEGER
AS
BEGIN
SET NOCOUNT ON;
IF(SELECT COUNT(*) FROM QT_Community WHERE ID = @ID) = 0
INSERT INTO QT_Community(Name, [Description], Picture, [Owner], Venue) VALUES(@Name, @Description, @Picture, @Owner, @Venue);
ELSE
UPDATE QT_Community SET Name = @Name, [Description] = @Description, Picture = @Picture, [Owner] = @Owner, Venue = @Venue WHERE ID = @ID;
SELECT * FROM QT_Community WHERE ID = @@IDENTITY;
END
What's wrong with this code? Isn't VARBINARY
a byte[]
?
This code works when executing on SQL Server Management Studio.
DECLARE @X varbinary(20)
Set @X = CAST('Testing' As varbinary(20))
EXECUTE [QP_AddCommunity] 'aaaaa', 'descricao', @X, 216, NULL, 0;
But when calling from the GetSqlQuery
method with something on the byte[]
the transaction says it's not active and not dirty. BUT if the byte[]
is null
it works as it should.
In Sql Server, use image data type or varbinary data type, to store byte array data.
DECLARE @tmp varbinary(max); SET @tmp = CONVERT(varbinary, '1234567890abcdef', 2); EXEC BinaryDemo @BinaryData=@tmp; What I'd like to do is skip the intermediate steps and invoke the procedure like: EXEC BinaryDemo @BinaryData=CONVERT(varbinary, '1234567890abcdef', 2);
i found that it is impossible as this answer shows
Hello gaurav, currently our GetSqlQuery method cannot operate properly with parameters of type LongVarBinary or VarBinary, thus making it impossible for the stored procedure to work as expected. We are aware of this problem and we are working on fixing it. As a work around you should try and use Linq to achieve your goal. Greetings, Petar the Telerik team
Accordingly to this table it seems either BLOB
, BINARY
, VARBINARY
would be valid types for [] of primitive type
.
You could try to ask on their forums, maybe someone will be able to help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With