Click here to Skip to main content
15,915,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I want a way to add rows to a database based on some strings i have somewhere.
any easy linq query code to accomplish this? the database is already connected by :

public static DataClasses1DataContext database = new DataClasses1DataContext();

so I need codes from here.
Thanks
Posted
Comments
Pheonyx 21-Nov-13 4:05am    
You've not really told us anything of any real help... "Some rows, based on some string, I have somewhere".. What sort of strings? What sort tables, can you give an example of what you are trying to do exactly rather than this vague attempt at a "question".
TryAndSucceed 21-Nov-13 12:35pm    
Agreed with above comment. Not enough information to help. Atleast share your code.

1 solution

Sorry about the vague question.
Managed to figure it all out thou

Coursework new_course_work = new Coursework(); //new coursework
            new_course_work.Due_Date = this.dateTimePicker1.Value;//store selected date as due date
            new_course_work.Title = this.textBox1.Text;//store title from user entry
            new_course_work.Module_Code = moduleList.GetItemText(moduleList.SelectedItem);
            //store module from selection

            Globals.database.Courseworks.InsertOnSubmit(new_course_work);
            Globals.database.SubmitChanges();//submit the new coursework to database

            var query_ = from DataClasses1 in Globals.database.Enrols
                         where DataClasses1.Module_Code == new_course_work.Module_Code
                         select new {DataClasses1.Student_ID };//select every student ID registered on the module
            foreach (var item in query_)
            {
                Submission new_submission = new Submission();
                new_submission.Bar_Ref_ID = Globals.Bar_Ref_Gen(); //a newlyy generated bar ref ID 
                new_submission.CWRefID = new_course_work.CWRefID; //the CWRef ID is same as the original cw
                new_submission.Status = false; //the submission status is initially set at false
                new_submission.Student_ID = item.Student_ID;//the student ID is set for it

                Globals.database.Submissions.InsertOnSubmit(new_submission);
                Globals.database.SubmitChanges();//submit the new submission


Thats my code and it works fine. Incase any one with same problem could use mine to try and solve
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900