I am trying to pass a value to a Stored Proc, that value is the name of a table that I want the SP to create first by copying data from an exiting table then creating the PK for the new table. Here is the VB code behind that calls the SP, and below is the SP..... Dim myString As String = "tblLangEN" itemDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("myConnString").ToString() itemDataSource.InsertCommandType = SqlDataSourceCommandType.StoredProcedure itemDataSource.InsertCommand = "usp_createNewLangTable" ' Call stored procedure itemDataSource.InsertParameters.Add("langTable", myString.Trim())
Here is the SP....ALTER PROCEDURE usp_createNewLangTable /* ********************************************* */ @langTable varchar(50) AS SET NOCOUNT ON; DECLARE @sql varchar(max); BEGIN SET @sql = 'SELECT * INTO ' + @langTable +' FROM UniqueStringsMaster'; END print (@sql) EXECUTE(@sql); SET @sql = '' BEGIN SET @sql = 'ALTER TABLE ' + @langTable + ' ADD CONSTRAINT String_ID PRIMARY KEY (String_ID)' ; END print (@sql) EXECUTE(@sql); SET @langTable = Null; RETURN
Not sure why this is not working, it works in SQL Mgmt Studio