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. General Programming
  3. Visual Basic
  4. How Do I Insert Rows into a table dynamicly?

How Do I Insert Rows into a table dynamicly?

Scheduled Pinned Locked Moved Visual Basic
helpquestioncsharpdatabase
3 Posts 3 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.
  • R Offline
    R Offline
    r_mohd
    wrote on last edited by
    #1

    Hi all, Currently i am facing a problem when i try to insert rows in a table dynamicly. i using vb.net 2008 with mssql express 2008.here are the details of my codes USE [database] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO create PROCEDURE [dbo].[TestSp] ( @name nvarchar(50), @tb varchar(200) ) AS BEGIN SET NOCOUNT ON; execute ('insert into ' + @tb +'(xname)values(@name)') END exec testsp 'testtable1','Abcxyz' Error: Msg 137, Level 15, State 2, Line 1 Must declare the scalar variable "@name". please help me.

    rmshah Developer

    M N 2 Replies Last reply
    0
    • R r_mohd

      Hi all, Currently i am facing a problem when i try to insert rows in a table dynamicly. i using vb.net 2008 with mssql express 2008.here are the details of my codes USE [database] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO create PROCEDURE [dbo].[TestSp] ( @name nvarchar(50), @tb varchar(200) ) AS BEGIN SET NOCOUNT ON; execute ('insert into ' + @tb +'(xname)values(@name)') END exec testsp 'testtable1','Abcxyz' Error: Msg 137, Level 15, State 2, Line 1 Must declare the scalar variable "@name". please help me.

      rmshah Developer

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Notice how you included the table name in the SQL string, do the same for the @Name value as well. execute ('insert into ' + @tb +'(xname)values(' + @name +')') Also use pre tags when posting code - easier to read

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • R r_mohd

        Hi all, Currently i am facing a problem when i try to insert rows in a table dynamicly. i using vb.net 2008 with mssql express 2008.here are the details of my codes USE [database] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO create PROCEDURE [dbo].[TestSp] ( @name nvarchar(50), @tb varchar(200) ) AS BEGIN SET NOCOUNT ON; execute ('insert into ' + @tb +'(xname)values(@name)') END exec testsp 'testtable1','Abcxyz' Error: Msg 137, Level 15, State 2, Line 1 Must declare the scalar variable "@name". please help me.

        rmshah Developer

        N Offline
        N Offline
        N a v a n e e t h
        wrote on last edited by
        #3

        r_mohd wrote:

        execute ('insert into ' + @tb +'(xname)values(@name)')

        That's a poor practice. Your code is open to SQL injection attacks. You need read SQL Injection Attacks and Some Tips on How to Prevent Them[^].

        Navaneeth How to use google | Ask smart questions

        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