I’m using VB.NET AND SQL SERVER 2008
I’ve Array of object that I need to INSERT into SQL SERVER 2008 this is the object
this object will be Inserted in to three tables :
-
First table will have the report information : [ id ,reportName , description , style ] after inserting this information i’ll use the
@@IDENTITYof thisRowasFKfor the second Table -
SECOND table : [id , id_first_table, comment,complete,finished,name,started,outcome]
Question will come with the third table
How can i loop through the checklist Element and inserting it to the third table using the second table id till the end of element
like :
[id , id_second_table, 101 ,820]
[id , id_second_table'sameid', 101,831]
Here is what i have tried :
DECLARE @reportId INT , @fieldId INT
INSERT INTO
dbo.tblReport(strReportName,strReportDescription,strReportStyle,
strScource,dtmCreated)
VALUES ('caustic' , 'titration caustic', 'simple table' ,'user' , getdate())
SELECT @reportId = @@IDENTITY
INSERT INTO dbo.tblReportFields
(lngReports,strFieldName,bolComment,bolComplete,bolFinished,
bolOutCome,bolStarted,bolUser)
VALUES (@reportId ,'caustic titration' , 1,0,1,0,0,0)
SELECT @fieldId = @@IDENTITY
--LOOP AND INSERT ALL THE checklist Element
INSERT INTO dbo.tblReportTask (lngReportFields,lngChecklist,lngTask)
VALUES (@fieldId, 814 , 1443)
any ideas on the best way of doing this will be also considered
Okay, your info was a little hard to work with since your Object and SQL Statements don’t quite match up. However, here is basically how you do it. I hope you can relate it back to your problem.
This is how you insert the Report and ReportFields tables. I didn’t include the SQL for the ReportFields table since it is similar to the Report one.