Multiple database inserts

Results 1 to 2 of 2

Thread: Multiple database inserts

  1. #1
    Join Date
    Dec 1969

    Default Multiple database inserts

    Hello, i&#039;m trying to insert multiple rows in a database with a loop. <BR><BR>Here&#039;s how it works:<BR><BR>With the forum, you can insert a poll. Thats a question and multiple questions. With a literalcontrol the user van insert a new answer. Sometimes there are 3 answers to a poll and sometimes there are 15 answers to a poll. The answercount is unlimited.<BR><BR>When the forum is post back, I want to collect all the pollanswer so I can insert then in the database. The number of answers are maintained in the viewstate so I know how many answers there are. <BR><BR>I did not manage to insert the questions in the database because could read them out.<BR><BR>I tried to put the answers in a array but that didn&#039;t work.<BR><BR>The id of the textfield of the answer is txtPollAnswer1, txtPollAnswer2, txtPollAnswer3, txtPollAnswer4 and so on.<BR><BR>Here my code that doesn&#039;t work:<BR><BR>PollAnswersCount = ViewState( "PollAnswerCount" )<BR> <BR>For intCounter = 0 To ViewState( "PollAnswerCount" ) - 1<BR> a = "txtPollAnswer" & intCounter<BR> Response.Write(a)<BR> arrPollAnswers.Insert( intCounter,a.Text)<BR> response.write (arrPollAnswers(intCounter))<BR>Next<BR><BR>Please help me. <BR><BR>I need tot insert the contents of all the answers later on with a insert query

  2. #2
    Join Date
    Dec 1969

    Default RE: Multiple database inserts

    just a thought: you might cosider creating a datagrid on your page to hold the info from the database. You can set all of the columns visibility to false, so the use won&#039;t see it: it is just a storage device, in this case. The benefit is that, in conjunction with a dataset, you can more easily store data in a form that is consistent with the database that you want to insert info to. Then, when you are ready, you can use a dataAdapter to generate the insert statements to the DB. The DataSet will "sync up" with the DB to determine what new info was added, and you can avoid craeating aloop to insert the new info. Obviously, this is not a detailed answer to your question, but with some research into how to properly use the DataAdapter, DataSet, and DataGrid, I think you will be able to solve your problem.<BR><BR>PS: maintain the state of the DataSet by keeping it in a session variable, that you update everytime the DAtaSet is updated. This suggestion makes liberal use of the PostBack method to update the DAtaSet

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts