Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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>
Posted
Updated 17-Feb-14 21:44pm
v2

"when accidentally the database got changed" is pretty significant.

Don't write code like that: always specify the columns into which you want to insert your data - if you don't, then SQL has to go in parameter order - so if the DB gets changed, and the column order no longer matches the parameter order, it tries to insert the wrong data in the wrong column, and you get an error like this - if you are lucky. If you are unlucky, you don't get an error, but instead it works, and you get a database full of mixed up data columns: City name in the first name column, invoice number in the bill total column, that kind of thing. Nasty...

Instead of writing inserts like this:
SQL
INSERT INTO MyTable VALUES (1, 2, 'Joe Smith')
Use named columns instead:
SQL
INSERT INTO MyTable (Id, Age, UserName) VALUES (1, 2, 'Joe Smith')

And there is a good chance your problem will disappear.
 
Share this answer
 
Comments
raxhemanth 18-Feb-14 3:45am    
even i change the way u have suggested still getting the same error please check my updated querey
raxhemanth 18-Feb-14 4:05am    
Got it griff thanks for your concern about my issue thank you somuch
OriginalGriff 18-Feb-14 4:34am    
You're welcome!
You are getting error because of column sequence got mismatch.

simply change query with column name mention in that like

SQL
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)
 
Share this answer
 
Comments
raxhemanth 18-Feb-14 3:45am    
even i change the way u have suggested still getting the same error please check my updated querey
raxhemanth 18-Feb-14 4:05am    
Got it prakash thanks for ur concern about my issue thanks alot
Please post your table structure and execute query data.
 
Share this answer
 
Comments
OriginalGriff 18-Feb-14 4:34am    
Reasons for my vote of one: this is not an answer. If you want extra information, use the "have a question or comment?" button at the top - posting this as a "solution" looks like rep point hunting, which is frowned upon.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900