ASP.net application advice needed
im biulding a ASP.net application, which is connected to a database. the database design is as follows
**Users Table**
UserID `(PK) autonumber`
Username
**Question Table**
QuestionID `(PK) autonumber`
QuestionNumber
QuestionText
**Questionnaire Table**
QuestionnaireID `(PK) autonumber`
UserID `(FK) User Table`
Date
**Feedback Table**
FeedbackID `(PK) autonumber`
QuestionnaireID `(FK) Questionnaire Table`
QuestionID `(FK) Questions Table`
Answer
Comment
please can some one advise me on how I should go about inserting data into 开发者_运维技巧the questionnaire table and the feedback table. I know that the questionnaire table needs to be updated first. but the Questionnaire ID is linked to the feedback table, so how do I go about updating both tables ?
Look at using Linq2Sql (In your project add a new Linq to Sql Classes dbml file and drag your tables onto it from the server exploter), it will map your tables to classes and a datacontext, which you can use to create new data objects to update your tables. It will automatically track and insert the necessary rows and manage the relationships between them
DataContext db = new DataContext();
Questionnaire q = new Questionnaire();
q.UserId = 1234;
Feedback f = new Feedback();
f.Questionnaire = q;
db.Feedbacks.InsertOnSubmit(f);
db.SubmitChanges();
A great place to start is with Scott Gu's introduction on his blog
http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx
精彩评论