Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SPROC: Insert only writing first char into a varchar (15) field??

SPROC: Insert only writing first char into a varchar (15) field??

Scheduled Pinned Locked Moved Database
csharpdatabaseasp-netquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 3400231
    wrote on last edited by
    #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

    B P N 3 Replies Last reply
    0
    • U User 3400231

      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

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      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.

      U 1 Reply Last reply
      0
      • U User 3400231

        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

        P Offline
        P Offline
        Paddy Boyd
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • U User 3400231

          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

          N Offline
          N Offline
          nelsonpaixao
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • B Blue_Boy

            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.

            U Offline
            U Offline
            User 3400231
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups