Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert a javascript array into a SQL table
    primarykey
    data
    text
    <p>Sorry for the vague title but I'm not sure at all how to go about this. I have a jquery auto complete text box on the page that allows users to search and add company names to a comma delimited list. I can use javascript to parse the values up and create an array of integers (id's for each company). When I do a javascript alert it will display the company ID's in an array of integers (9,20,19,17). The next step I have NO idea how to go about it how to get those into my insert stored procedure and loop through them with the scope_identity from the first table insert.</p> <p>Below is my current stored procedure. Right now I just have a hard coded supplier ID for the second insert but I need to be able to add a row for each selected company to the association table. So ideally it would loop through all four selected companies and add the company ID along with the scope identity from the insert on the nominations table. All the other data on the page will be added directly from asp.net controls and I don't know how to get the javascript array info over to the SP...Any guidance or direction would be greatly appreciated..</p> <pre><code>CREATE PROCEDURE dbo.NewNomination @ProviderFirstName VARCHAR (30)=NULL, @ProviderLastName VARCHAR (30)=NULL, @providerCompany VARCHAR (30)=NULL, @providerTitle VARCHAR (30)=NULL, @providerEmail VARCHAR (30)=NULL, @providerPhone VARCHAR (30)=NULL, @UseMyName BIT, @MakeCall BIT, @new_identity INT = NULL OUTPUT AS BEGIN SET NOCOUNT ON; INSERT INTO dbo.nomination ( ProviderFirstName , ProviderLastName , providerCompany , providerTitle , providerEmail , providerPhone , UseMyName , MakeCall ) VALUES ( @ProviderFirstName , @ProviderLastName , @ProviderCompany , @providerTitle , @providerEmail , @providerPhone , @UseMyName , @MakeCall ) SET @new_identity = SCOPE_IDENTITY(); INSERT INTO dbo.NominationSupplier ( NominationID , SupplierID , fname , lname , email ) VALUES ( @new_identity , 28 , @ProviderFirstName , @ProviderLastName , @providerEmail ) COMMIT TRAN END GO </code></pre> <p>`</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COUse a server side application written in .net, php, coldfusion or something like that. Pass the list to that application and use it to talk to your database.
      singulars
    2. COOK..I think I'm a bit further down the road..just hope it's the right road. I've passed the jquery array values to a hidden asp.net field on the page so I can tie into that to insert it into my DB via the stored procedure. So now I just need to figure out the stored procedure and how to loop through the values of that array (example 2,6,8,10) and insert them as individual inserts into the association table along with the Scope_Identity ID. Not sure if that logic is done somewhere in the SP or in javascript. I'm assuming it has to be in the SP as that's where the Scope_Identity ID is generated.
      singulars
    3. COOK...may be heading down the wrong road, I'm finding that through jquery I'm just adding the seperate array values to hidden inputs and can't put them in asp.net hidden controls obviously..so I still can't pull them in via the stored proc. Not sure where to go next. I haven't found any clear documentation on how to use ajax for this. it seems that I'm already using a stored procedure to enter the data and get the scopeidentity, so I'm unclear on where ajax comes in. Would I be entering data into SQL in multiple ways?
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload