Hi all!!!
I am storing a document in database. i want to enter null value to database if there is no document attached for the transaction. this is my code
If (fuAttachedDoc.HasFile) Then
Dim file As HttpPostedFile = fuAttachedDoc.PostedFile
If file.ContentLength > 0 Then
Dim size As Integer = file.ContentLength
obj.Size = size
Dim name As String = file.FileName
Dim position As Integer = name.LastIndexOf("\")
name = name.Substring(position + 1)
obj.Aname = name
Dim contentType As String = file.ContentType
obj.ContentType = contentType
Dim fileData As Byte() = New Byte(size - 1) {}
obj.Data = fileData
file.InputStream.Read(fileData, 0, size)
End If
Else
obj.Size = 0
obj.Aname = ""
obj.ContentType = ""
obj.Data = 0
End If
now it shows error that value of type int cannot me converted to 1-d array. i set obj.Data= Nothing then it shows that stored procedure expects a value. please tell me how can i store null to db if there is no file attached. Data is of type Byte(). I tried using obj.Data =DBNull.Value instead of zero but the same error exists after changing the code
here is the code for stored procedure
ALTER procedure [dbo].[sp_insert_details_employeeWithAttachment]
@unqId bigint,
@empId bigint,
@joining_dt datetime,
@deptID bigint,
@subDeptID bigint,
@sectionId bigint,
@postId bigint,
@scaleId bigint,
@postType nvarchar(1),
@BasicPay decimal(10,2),
@GradePay decimal(10,2),
@PayBand decimal(10,2),
@Aname nvarchar(100),
@ContentType varchar(50),
@Size bigint,
@Data varbinary(max)
--,@attachedDoc image
AS
BEGIN
if @unqId=0
BEGIN
BEGIN
SET @unqId=(Select ISNULL(MAX(unqid),'0')+1 from details_employee)
END
INSERT INTO [details_employee]
([unqId],[empId],[joining_dt],[deptID],[subDeptID],[sectionId] ,[postId],[scaleId],[postType],[BasicPay],[GradePay],[PayBand], [AName] ,[ContentType] ,[Size] ,[Data]
--,attachedDoc
)
VALUES(@unqId,@empId,@joining_dt,@deptID,@subDeptID,@sectionId ,@postId,@scaleId,@postType,@BasicPay,@GradePay,@PayBand
, @Aname ,@ContentType,@Size,@Data
)
END
else
BEGIN
UPDATE [details_employee] SET
empId=@empId,postId=@postId,joining_dt=@joining_dt,deptID=@deptID,subDeptID=@subDeptID,scaleId=@scaleId,postType=@postType, sectionId=@sectionId ,
BasicPay=@BasicPay,GradePay=@GradePay,PayBand=@PayBand ,AName=@Aname,ContentType=@ContentType,Size=@Size ,Data=@Data
--, attachedDoc=@attachedDoc
WHERE unqId=@unqId
END
END