I have created a user defined type (with script to CREATE) given below:
CREATE TABLE [dbo].[EmployeeMasters](
[ID] [int] IDENTITY(1,1) NOT NULL,
[EmployeeID] [varchar](max) NOT NULL,
[EmployeeFName] [varchar](max) NOT NULL,
[EmployeeLName] [varchar](max) NOT NULL,
[Photo] [image] NOT NULL)
On the same database I have created a procedure that uses this type:
create PROCEDURE EmpQuli_INSERT @EmployeeID varchar(Max),@EmployeeFName VARCHAR(MAX), @EmployeeLName VARCHAR(MAX),@Photo IMAGE AS BEGIN DECLARE @NEWID VARCHAR(10);
DECLARE @PREFIX VARCHAR(MAX);
SET @PREFIX = UPPER(SUBSTRING('STR',1, 3)) SELECT @NEWID = (@PREFIX + replicate('0', 3 -len(CONVERT(VARCHAR,N.OID + 1))) + CONVERT(VARCHAR,N.OID + 1)) FROM (SELECT CASE WHEN MAX(T.TID) IS null then 0 else MAX(T.TID) end as OID FROM (SELECT SUBSTRING(EmployeeID, 3, 1) as PRE_FIX,SUBSTRING(EmployeeID, 3, LEN(EmployeeID))as TID FROM EmployeeMasters) AS T WHERE T.PRE_FIX = @PREFIX) AS N
insert into EmployeeMasters values(@NEWID,@EmployeeFName, @EmployeeLName, @Photo);
end
And I try to insert a value in c# I getting operand type clash : image is incomplate with varchar(max) in sql server The c# code is:
EmployeeFName.Value = textBox_emp_Fname.Text;
EmployeeLName.Value = textBox_emp_Lname.Text;
Photo.Value =img_arr1;
AddEmployee.CommandText = "EmpQuli_INSERT @EmployeeFName, @EmployeeLName, @Photo";
I don't know who to fix it. Please help me because I have to submit my final year project on June first week but now I struggle this exception please help....
You're missing a column in your insert statement:
insert into EmployeeMasters values(@NEWID,@EmployeeFName, @EmployeeLName, @Photo);
EmployeeID is missing, so @Photo
tries to save into @EmployeeLName
, which is incompatible. Even if it weren't, you'd still be missing EmployeeID
, which is NOT NULL
.
I'd suggest using the explicit insert syntax instead of relying on the auto-supplied columns:
insert into EmployeeMasters(EmployeeID, EmployeeFName, EmployeeLName, Photo)
values (@NewID, @EmployeeFName, @EmployeeLName, @Photo);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.