开发者

Storing multiple values with C# to a SQL database

开发者 https://www.devze.com 2023-03-24 05:05 出处:网络
I\'m looking for advice on the best way to store multiple values using C# and a SQL database, specifically MS SQL Server Express. I can get data into table A and B, but I\'m not sure how to store all

I'm looking for advice on the best way to store multiple values using C# and a SQL database, specifically MS SQL Server Express. I can get data into table A and B, but I'm not sure how to store all 10 steps to the database when form 2 is filled out.

The way the application works is a user chooses an item from a combobox on form 1, presses the submit button. Then table A and table B get updated. Once the tables have their values, form 2 opens up and the user fills in the data and submits it to be stored in table B.

As you can see in form 2, I can't imagine having to create 30 radio buttons and 22 textbox fields in table B for each step. Any advice on what direction to take is much appreciated.

EDIT: I know the question was confusing, I apologize I'm confused myself! Basically I just want to store the 10 steps related to a unique id. So when I do a query for say I开发者_运维知识库D 1 it shows the 10 steps associated with that ID.

Using:

Visual Studio Pro 2010

SQL Express 2008

LINQ for the queries to the DB.

Form 2


You can add table C to store the answers. Table B will have an ID field, that will be used by table C to identify the related record in table B.

Table B:

ID, ...
1 , ...
2 , ...

Table C

ID, questionID, Answer
1 , 1         , "value"
2 , 1         , "value"
3 , 1         , "value"
...
10, 2         , "value"
11, 2         , "value"

The questionID field is the relation to table B, and you can determine the answer order by ID field


As you can see in form 2, I can't imagine having to create 30 radio buttons and 22 textbox fields in table B for each step

From your form, it looks like you need (maybe) 5 fields in Table B.

1) QuestionID (int, foreign key)
2) Answer1 (n/a textbox)
3) Answer2 (radiobutton selection)
4) Answer3 (txt)
5) Answer4 (txt)

Then, you need a lookup table for your questions -- Table C.

1) QuestionID (int, primary key)
2) Question Text (txt)

This sounds like a database design question, not a c# / Sql-server-2008 question...unless I'm misreading it.

0

精彩评论

暂无评论...
验证码 换一张
取 消