Note that there are some explanatory texts on larger screens.

plurals
  1. POBenefits of LINQ?
    primarykey
    data
    text
    <p>I have been fretting over this problem too long, however as I have not had any definitive answers, I will try to state the situation again, in a clearer fashion.</p> <p>I have a questionaire, which allows administrators to add different categories and different questions for each category, therefore on inserts for each categories I cannot hard code parameters as I do not know how many questions the user will be answering.</p> <p>Right now I have an SP which inserts (or updates) one row;</p> <pre><code>CREATE PROCEDURE [dbo].[insertResults] @userId nvarchar(10), @groupId INT , @questionId INT, @answer INT AS BEGIN SELECT * FROM answers WHERE userId = @userId AND questionId = @questionId IF @@ROWCOUNT=0 INSERT INTO answers ( userId, groupId, questionId, answer ) VALUES ( @userId, @groupId , @questionId, @answer ) ELSE UPDATE answers SET answer = @answer WHERE userId = @userId AND questionId = @questionId END </code></pre> <p>then in C# I loop through all the questions;</p> <pre><code>foreach (GridViewRow gvr in GridView1.Rows) { var rb = gvr.FindControl("answers_list") as RadioButtonList; var quest = rb.SelectedValue; if (quest == "") { quest = "0"; } int questionId = Convert.ToInt32(GridView1.DataKeys[gvr.RowIndex].Values[0].ToString()); int groupId = Convert.ToInt32(GridView1.DataKeys[gvr.RowIndex].Values[1].ToString()); int question = Convert.ToInt32(quest); var objDB01 = new dbconn(); const string strSQL = "insertResults"; objDB01.objCommand.Parameters.AddWithValue("@userId", logonName); objDB01.objCommand.Parameters.AddWithValue("@groupId", groupId); objDB01.objCommand.Parameters.AddWithValue("@questionId", questionId); objDB01.objCommand.Parameters.AddWithValue("@answer", question); try { objDB01.GetNonQuery(strSQL); } finally { objDB01.Dispose(); } } </code></pre> <p>I have asked my own server team if opening and closing the DB so many times is bad coding (sometimes there can be over 100 people answering over 100 questions simultaneously) but I cannot get an answer. I have asked here if there is a more efficient solution or if the use of LINQ in this scenario can improve performance - but I cannot get an answer.</p> <p>I may not have the knowledge, but I am trying to learn to programme elegantly and your help would be most appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload