C# and updating 3 linked tables in SQL server

Associate
Joined
27 Jan 2005
Posts
1,396
Location
S. Yorks
I have the following situation whereby I have three linked tables in sql server:

Table1:
ProjectId
ProjectTitle

Table2:
Id
ProjectId
DateAdded
ColRef
SPos
SCode

Table3:
AmmendId
ProjectId
ColRef
SPos
SCode
DateAmmended
ByWho

What I want to do is update these tables with the relevant data but not quite sure how? Do I have to do three seperate insert queries or just one?

Am new to all this so any help would be greatfully received.

Matt
 
Thanks for the replys guys.

Have done a little Linq work but just queryinig tables, how do I get it to write to a database?? As I said am new to this.

ORM???transaction scope??? soorry don't understand these.


Matt
 
Ok, thanks for help think I have it now.

One other question regarding LINQ, if I use the following to return a projectID:

Code:
 var results = (from p in db.tbl_ShearFix_Projects
                           select p.ProjectId ).Distinct();

            Array ar = results.ToArray();

I can then pass that array to a combobox and all is well.

However I want to be able to search for a specific projectId or all projectID's so have tried this:
Code:
 var results = (from p in db.tbl_ShearFix_Projects
                           select new { p.ProjectId }).Distinct();

if (pid == "%")
            {// Select everything
                results = results.AsQueryable().Where(x =>                                
                    x.ProjectId != "%");
            }
            else
            {
                results = results.AsQueryable().Where(x =>
                    x.ProjectId == pid);
            }

This works but the resultant array is as follows:

ar[0] { ProjectId = 111111 }
ar[1] { ProjectID = 222222 }

Thus the array is filled with the column name as well as the ID. How do I just return the ID???

regards,

Matt
 
Thanks for all of your help, got it working, all apart from updating a record in a database.

The fields I am trying to update form part of a composite key, but when I submit the changes it errors. Reading various websites it seems this is a limitation with LINQ. Doing the same with an SQL command or using Access the changes are fed to the backend sql server database with no errors.

What work arounds do you guys use when updating database fields that are part of the key?

Matt

P.S. Can anyone point me to a good website explaining how to generate a report as I am bemused by this.
 
Last edited:
Back
Top Bottom