SPROC: Insert only writing first char into a varchar (15) field??
-
Hi I have written a stored procedure as follows: ALTER PROCEDURE dbo.VehiclesInsert ( @TypeId int = 4, @Reg varchar = 15, @Mileage decimal = 9, @Price money = 8, @Fuel int = 4, @Colour varchar = 80, @BodyShape int = 4, @Doors int = 4, @Warranty int = 4, @MoreInfo text, @RegLetter int=4, @CreatedBy int=4 ) AS INSERT INTO Vehicles (TypeId,Reg,Mileage,Price,Fuel,Colour,BodyShape,Doors,Warranty,MoreInfo,RegLetter,CreatedBy) VALUES (@TypeId,@Reg,@Mileage,@Price,@Fuel,@Colour,@BodyShape,@Doors,@Warranty,@MoreInfo,@RegLetter,@CreatedBy) RETURN Although I have defined the Reg variable as Varchar 15, it only writes the first letter into the Reg field of my DB. I am using ASP.NET and c# to call the sproc - I even tried hard-coding the parameter value e.g: objCmd.Parameters.Add("@Reg", "Test Reg"); However it still only adds "T" into the Reg field. I can manually add Test Reg into the field in the DB table so the field lengths all seem to be ok. I'm very new to SProcs so please excuse me if I'm missing something obvious! Thanks Lorna
-
Hi I have written a stored procedure as follows: ALTER PROCEDURE dbo.VehiclesInsert ( @TypeId int = 4, @Reg varchar = 15, @Mileage decimal = 9, @Price money = 8, @Fuel int = 4, @Colour varchar = 80, @BodyShape int = 4, @Doors int = 4, @Warranty int = 4, @MoreInfo text, @RegLetter int=4, @CreatedBy int=4 ) AS INSERT INTO Vehicles (TypeId,Reg,Mileage,Price,Fuel,Colour,BodyShape,Doors,Warranty,MoreInfo,RegLetter,CreatedBy) VALUES (@TypeId,@Reg,@Mileage,@Price,@Fuel,@Colour,@BodyShape,@Doors,@Warranty,@MoreInfo,@RegLetter,@CreatedBy) RETURN Although I have defined the Reg variable as Varchar 15, it only writes the first letter into the Reg field of my DB. I am using ASP.NET and c# to call the sproc - I even tried hard-coding the parameter value e.g: objCmd.Parameters.Add("@Reg", "Test Reg"); However it still only adds "T" into the Reg field. I can manually add Test Reg into the field in the DB table so the field lengths all seem to be ok. I'm very new to SProcs so please excuse me if I'm missing something obvious! Thanks Lorna
-
Hi I have written a stored procedure as follows: ALTER PROCEDURE dbo.VehiclesInsert ( @TypeId int = 4, @Reg varchar = 15, @Mileage decimal = 9, @Price money = 8, @Fuel int = 4, @Colour varchar = 80, @BodyShape int = 4, @Doors int = 4, @Warranty int = 4, @MoreInfo text, @RegLetter int=4, @CreatedBy int=4 ) AS INSERT INTO Vehicles (TypeId,Reg,Mileage,Price,Fuel,Colour,BodyShape,Doors,Warranty,MoreInfo,RegLetter,CreatedBy) VALUES (@TypeId,@Reg,@Mileage,@Price,@Fuel,@Colour,@BodyShape,@Doors,@Warranty,@MoreInfo,@RegLetter,@CreatedBy) RETURN Although I have defined the Reg variable as Varchar 15, it only writes the first letter into the Reg field of my DB. I am using ASP.NET and c# to call the sproc - I even tried hard-coding the parameter value e.g: objCmd.Parameters.Add("@Reg", "Test Reg"); However it still only adds "T" into the Reg field. I can manually add Test Reg into the field in the DB table so the field lengths all seem to be ok. I'm very new to SProcs so please excuse me if I'm missing something obvious! Thanks Lorna
Mmm. Blue boy is right, your equals to syntax is just assigning default values to the parameters. Your varchar is being declared with the default length of 1.
-
Hi I have written a stored procedure as follows: ALTER PROCEDURE dbo.VehiclesInsert ( @TypeId int = 4, @Reg varchar = 15, @Mileage decimal = 9, @Price money = 8, @Fuel int = 4, @Colour varchar = 80, @BodyShape int = 4, @Doors int = 4, @Warranty int = 4, @MoreInfo text, @RegLetter int=4, @CreatedBy int=4 ) AS INSERT INTO Vehicles (TypeId,Reg,Mileage,Price,Fuel,Colour,BodyShape,Doors,Warranty,MoreInfo,RegLetter,CreatedBy) VALUES (@TypeId,@Reg,@Mileage,@Price,@Fuel,@Colour,@BodyShape,@Doors,@Warranty,@MoreInfo,@RegLetter,@CreatedBy) RETURN Although I have defined the Reg variable as Varchar 15, it only writes the first letter into the Reg field of my DB. I am using ASP.NET and c# to call the sproc - I even tried hard-coding the parameter value e.g: objCmd.Parameters.Add("@Reg", "Test Reg"); However it still only adds "T" into the Reg field. I can manually add Test Reg into the field in the DB table so the field lengths all seem to be ok. I'm very new to SProcs so please excuse me if I'm missing something obvious! Thanks Lorna
try this ok?
sql_cmd.Parameters.Add("@country", SqlDbType.varchar).Value = textbox_GrandPrixCountry.text;
what do you get from this???:confused:
Member 3402886 wrote:
objCmd.Parameters.Add("@Reg", "Test Reg");
nelsonpaixao@yahoo.com.br trying to help & get help
-
try make this changes:
. . . @Reg varchar (15), . . . @Colour varchar (80), . . .
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
Thanks - that was the problem (I knew it would be something obvious :-)) I actually had int = 4 in other SProcs so I've changed those values to just int now in case anyone else is interested and they all work fine.