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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Procedure and Codebehind Problem

Procedure and Codebehind Problem

Scheduled Pinned Locked Moved ASP.NET
comhelptutorialquestion
3 Posts 2 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.
  • M Offline
    M Offline
    monika_vasvani
    wrote on last edited by
    #1

    Hi all I have created one procedure: CREATE PROCEDURE [dbo].[dynamic_insert](@table varchar(50),@parameter nvarchar(4000)) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; set @opration='insert into '+@table+'(+@testTable+) values(+ @parameter +)' end My front end code is: com.Parameters("@table").Value = "order1" com.Parameters.Add("@parameter", SqlDbType.NVarChar) com.Parameters("@parameter").Value = c2.cust_id & "," & c2.item_id & "," & c2.cust_items & "," & c2.item_name c2 is my class object. My problem is:when i assign values in parameter field,it takes as string. So data is not inserted. example: c2.cust_id = 1 c2.item_id = 1 c2.cust_items = "cd" c2.item_name = "pen" com.Parameters("@parameter").Value ="1,1,cd,pen" It's not possible to insert string. what i do?is there any another datatype? or another way? Thanks monika

    S 2 Replies Last reply
    0
    • M monika_vasvani

      Hi all I have created one procedure: CREATE PROCEDURE [dbo].[dynamic_insert](@table varchar(50),@parameter nvarchar(4000)) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; set @opration='insert into '+@table+'(+@testTable+) values(+ @parameter +)' end My front end code is: com.Parameters("@table").Value = "order1" com.Parameters.Add("@parameter", SqlDbType.NVarChar) com.Parameters("@parameter").Value = c2.cust_id & "," & c2.item_id & "," & c2.cust_items & "," & c2.item_name c2 is my class object. My problem is:when i assign values in parameter field,it takes as string. So data is not inserted. example: c2.cust_id = 1 c2.item_id = 1 c2.cust_items = "cd" c2.item_name = "pen" com.Parameters("@parameter").Value ="1,1,cd,pen" It's not possible to insert string. what i do?is there any another datatype? or another way? Thanks monika

      S Offline
      S Offline
      Scott Dorman
      wrote on last edited by
      #2

      I have created one procedure:

      CREATE PROCEDURE [dbo].[dynamic_insert](@table varchar(50),@parameter nvarchar(4000))
      AS
      BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
      SET @opration='insert into '+@table+'(+@testTable+) values(+ @parameter +)'
      END

      My front end code is:

      com.Parameters("@table").Value = "order1"
      com.Parameters.Add("@parameter", SqlDbType.NVarChar)
      com.Parameters("@parameter").Value = c2.cust_id & "," & c2.item_id & "," & c2.cust_items & "," & c2.item_name

      c2 is my class object. My problem is when I assign values in parameter field, it takes as string. So data is not inserted. example:

      c2.cust_id = 1
      c2.item_id = 1
      c2.cust_items = "cd"
      c2.item_name = "pen"
      com.Parameters("@parameter").Value ="1,1,cd,pen"

      It's not possible to insert string. what i do? is there any another datatype? or another way?

      Scott Dorman

      Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


      Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

      1 Reply Last reply
      0
      • M monika_vasvani

        Hi all I have created one procedure: CREATE PROCEDURE [dbo].[dynamic_insert](@table varchar(50),@parameter nvarchar(4000)) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; set @opration='insert into '+@table+'(+@testTable+) values(+ @parameter +)' end My front end code is: com.Parameters("@table").Value = "order1" com.Parameters.Add("@parameter", SqlDbType.NVarChar) com.Parameters("@parameter").Value = c2.cust_id & "," & c2.item_id & "," & c2.cust_items & "," & c2.item_name c2 is my class object. My problem is:when i assign values in parameter field,it takes as string. So data is not inserted. example: c2.cust_id = 1 c2.item_id = 1 c2.cust_items = "cd" c2.item_name = "pen" com.Parameters("@parameter").Value ="1,1,cd,pen" It's not possible to insert string. what i do?is there any another datatype? or another way? Thanks monika

        S Offline
        S Offline
        Scott Dorman
        wrote on last edited by
        #3

        You can't execute dynamic SQL like this. I believe you would need to call the "EXEC" function on the generated SQL. What is the actual SQL statement you want executed? Where does the @testTable parameter come from? Why are you not just creating a single stored procedure to handle inserts into the table and simply calling that, passing the appropriate parameters as discrete values?

        Scott Dorman

        Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


        Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

        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