Forms and Databases

T

Tom

Hello

I am currently making forms to get information into my SQL Server database. However the databae has been normalised and I need to put data into different tables. Is there a way of either sending data from a from in to different tables or storing data (for example an ID number) and using it on different forms? It can't be a hidden field or anyhting like that as it will need to be a new number for each entry

Many thank
Tom
 
J

Jon Spivey

Hi Tom,

You'd need to write a stored procedure to this, something aling these lines

Create Procedure spInsert
@Var1 varchar(255),
@Var2 varchar(255)
AS
Declare @NewID int
set nocount on
insert table1(field1) values(@Var1)
set @NewID = scope_identity()
insert table2(id,field1) values(@NewID, @Var2)
set nocount off

and you'd call it with a custom query like this
exec spInsert '::Field1::', '::Field2::'

Does that get you started?


--
Cheers,
Jon
Microsoft MVP - FP

wrote:
 
T

Tom

Thanks Jon

Where do I use this code and how? I tried looking in the help about stored procedures but to no avail

Tom
 
J

Jon Spivey

Hi Tom,

Fire up Enterprise Manager expand your database right click on Stored
Procedures - New Store Procedure and you can write your code in that window.
You can also do the same job in Visual Studio if you have it - thats what I
use, I don't touch Enterprise Manager unless I absolutely have to.

If stored procedures are new to you you might want to do a bit of reading
first - here's a good place to start
http://www.aspfaq.com/show.asp?id=2201
 
Top