本文介绍了我执行存储过程时为什么会出现隐式转换错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建过程Sp_InsertStudentDetails

@Adno int,@ First_name varchar(30),@ Last_name varchar(30),@ Gender varchar(10),@ Dateof_birth Date,@ Dateof_joining Date,@ Father_name varchar (30),@ Mother_name varchar(30),@ Occupation varchar(20),@ Branch varchar(10),@ Parent_mobilenumber bigint,@ Religion varchar(10),@ Caste varchar(20),@ House_number varchar(10), @Village_name varchar(20),@ District_name varchar(20),@ State_name varchar(20),@ Pincode int,@ Academic_year varchar(10),@ Image_file varbinary(MAX),@ Section Varchar(20)

as

begin

插入Student_Registration(Admission_number,First_name,Last_name,Gender,Dateof_birth,

Dateof_joining,Father_name,Mother_name,Occupation ,分支,宗教,种姓,House_number,

village_name,District_name,State_name,pincode,Academic_year,image_file,Parent_mobilenumber,

Section)值(@Adno,@ First_name,@ Last_name,@ Gender,@ Dateof_birth,@ Dateof_joining,

@ Father_name,@ Mother_name,@ Occupati on,@ Branch,@ Parent_mobilenumber,@ Religion,@ Caste,

@ House_number,@ Village_name,@ District_name,@ State_name,@ Pincode,@ Academic_year,

@Image_file ,@ Section)

结束





当我执行上面的查询时,我得到下面的错误但是当数据库被意外更改时,它已执行而没有任何错误。





< pre lang =" sql"> Msg 257,Level 16,State 3,Procedure Sp_InsertStudentDetails,第5行

不允许从数据类型varchar到varbinary(max)的隐式转换。使用CONVERT函数运行此查询。< / pre>

Create procedure Sp_InsertStudentDetails
@Adno int,@First_name varchar(30),@Last_name varchar(30),@Gender varchar(10),@Dateof_birth Date,@Dateof_joining Date,@Father_name varchar(30),@Mother_name varchar(30),@Occupation varchar(20),@Branch varchar(10),@Parent_mobilenumber bigint,@Religion varchar(10),@Caste varchar(20),@House_number varchar(10),@Village_name varchar(20),@District_name varchar(20),@State_name varchar(20),@Pincode int,@Academic_year varchar(10),@Image_file varbinary(MAX),@Section Varchar(20)
as
begin
Insert into Student_Registration(Admission_number,First_name,Last_name,Gender,Dateof_birth,
Dateof_joining,Father_name,Mother_name,Occupation,Branch,Religion,caste,House_number,
village_name,District_name,State_name,pincode,Academic_year,image_file,Parent_mobilenumber,
Section)values(@Adno,@First_name,@Last_name,@Gender,@Dateof_birth,@Dateof_joining,
@Father_name,@Mother_name,@Occupation,@Branch,@Parent_mobilenumber,@Religion,@Caste,
@House_number,@Village_name,@District_name,@State_name,@Pincode,@Academic_year,
@Image_file,@Section)
End


When i execute the query above i'am getting the error below but when accidentally the database got changed it has executed without any errors.


<pre lang="sql">Msg 257, Level 16, State 3, Procedure Sp_InsertStudentDetails, Line 5
Implicit conversion from data type varchar to varbinary(max) is not allowed. Use the CONVERT function to run this query.</pre>

推荐答案

INSERT INTO MyTable VALUES (1, 2, 'Joe Smith')

改为使用命名列:

Use named columns instead:

INSERT INTO MyTable (Id, Age, UserName) VALUES (1, 2, 'Joe Smith')



并且您的问题很可能会消失。


And there is a good chance your problem will disappear.


Insert into Student_Registration
(Adno,First_name,LastName,Gender,(add remaining columns))
values(@Adno,@First_name,@Last_name,@Gender,@Dateof_birth,@Dateof_joining,@Father_name,
@Mother_name,@Occupation,@Branch,@Parent_mobilenumber,@Religion,@Caste,
@House_number,@Village_name,@District_name,@State_name,@Pincode,@Academic_year
,@Image_file,@Section)



这篇关于我执行存储过程时为什么会出现隐式转换错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 13:01