我已經在SQL Server 2005,其中的參數之一是針對我已經使用varbinary
如表中的數據類型的圖像創建的插入命令的一個存儲過程對於員工詳細信息..SQL Server 2005的存儲過程錯誤
但是,當我加入這個參數在存儲過程中我收到以下錯誤 -
Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query.
存儲過程:
(
@Employee_ID nvarchar(10)='',
@Password nvarchar(10)='',
@Security_Question nvarchar(50)='',
@Answer nvarchar(50)='',
@First_Name nvarchar(20)='',
@Middle_Name nvarchar(20)='',
@Last_Name nvarchar(20)='',
@Employee_Type nvarchar(15)='',
@Department nvarchar(15)='',
@Photo varbinary(50)=''
)
insert into Registration
(
Employee_ID,
Password,
Security_Question,
Answer,
First_Name,
Middle_Name,
Last_Name,
Employee_Type,
Department,
Photo
)
values
(
@Employee_ID,
@Password,
@Security_Question,
@Answer,
@First_Name,
@Middle_Name,
@Last_Name,
@Employee_Type,
@Department,
@Photo
)
表結構:
Column Name Data Type Allow Nulls
Employee_ID nvarchar(10) Unchecked
Password nvarchar(10) Checked
Security_Question nvarchar(50) Checked
Answer nvarchar(50) Checked
First_Name nvarchar(20) Checked
Middle_Name nvarchar(20) Checked
Last_Name nvarchar(20) Checked
Employee_Type nvarchar(15) Checked
Department nvarchar(15) Checked
Photo varbinary(50) Checked
代碼在vb.net中調用存儲程序 - >
公共功能提交(BYVAL OBJ時的UserData,選擇BYVAL作爲字符串)作爲布爾
Using cnn As New SqlConnection(conn)
Using cmd As New SqlCommand
cmd.Connection = cnn
If opt = "Submit" Then
cmd.CommandText = "sp_emp_Registration"
End If
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@Employee_ID", obj.EmpID))
cmd.Parameters.Add(New SqlParameter("@Password", obj.Pwd))
cmd.Parameters.Add(New SqlParameter("@Security_Question", obj.SecQues))
cmd.Parameters.Add(New SqlParameter("@Answer", obj.Ans))
cmd.Parameters.Add(New SqlParameter("@First_Name", obj.Firstname))
cmd.Parameters.Add(New SqlParameter("@Middle_Name", obj.Middlename))
cmd.Parameters.Add(New SqlParameter("@Last_Name", obj.Lastname))
cmd.Parameters.Add(New SqlParameter("@Employee_Type", obj.EmpType))
cmd.Parameters.Add(New SqlParameter("@Department", obj.dept))
cmd.Parameters.Add(New SqlParameter("@Photo", obj.photo))
cnn.Open()
Try
If (cmd.ExecuteNonQuery() > 0) Then
cnn.Close()
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Using
End Using
End Function
我不知道該怎麼辦......任何人都可以給我一些建議或解決方案嗎? 在此先感謝。
你能提供SP嗎?聽起來像你已經創建了你的參數作爲varchar而不是varbinary。 –
沒有我用VARBINARY only..following是SP – user1670625
( 的Employee_ID爲nvarchar(10)= '', 密碼爲nvarchar(10)= '', SECURITY_QUESTION爲nvarchar(50)= '', 回答爲nvarchar( 50)= '', 將First_Name爲nvarchar(20)= '', Middle_Name爲nvarchar(20)= '', LAST_NAME爲nvarchar(20)= '', Employee_Type爲nvarchar(15)= '', 部爲nvarchar( 15)='', Photo varbinary(50)='' ) – user1670625