How to insert multiple records from different textboxes in a single table?

Sherryar

New Member
I have a view which consists of Eight \[code\]Textboxes\[/code\] for taking input of Question's Options text from user to submit in \[code\]DataBase\[/code\] Table.The values will go into table called Question_Options with the same Question_Id(F.K) which i saved in a hidden field now i have to submit all \[code\]TextBoxes\[/code\] values in \[code\]DataBase\[/code\], i want to do it through loop ....please any idea ....i am just a beginner.My HTML code is\[code\] <table> <tr> <td>Option 1 <asp:HiddenField ID="HF_QidOpt" runat="server" /> </td> <td> <asp:TextBox ID="txt_OptText" runat="server" Height="54px" TextMode="MultiLine" Width="310px"></asp:TextBox> </td> <td>Option 1 Description</td> <td> <asp:TextBox ID="txt_OptDesc" runat="server" TextMode="MultiLine" Height="54px" Width="310px"></asp:TextBox> </td> </tr> <tr> <td>Option 2</td> <td> <asp:TextBox ID="txt_OptText2" runat="server" Height="54px" TextMode="MultiLine" Width="310px"></asp:TextBox> </td> <td>Option 2 Description</td> <td> <asp:TextBox ID="txt_OptDesc2" runat="server" TextMode="MultiLine" Height="54px" Width="310px"></asp:TextBox></td> </tr> <tr> <td>Option 3</td> <td> <asp:TextBox ID="txt_OptText3" runat="server" Height="54px" TextMode="MultiLine" Width="310px"></asp:TextBox></td> <td>Option 3 Description</td> <td> <asp:TextBox ID="txt_OptDesc3" runat="server" TextMode="MultiLine" Height="54px" Width="310px"></asp:TextBox></td> </tr> <tr> <td>Option 4</td> <td> <asp:TextBox ID="txt_OptText4" runat="server" Height="54px" TextMode="MultiLine" Width="310px"></asp:TextBox></td> <td>Option 4 Description</td> <td> <asp:TextBox ID="txt_OptDesc4" runat="server" TextMode="MultiLine" Height="54px" Width="310px"></asp:TextBox></td> </tr> <tr> <td> <asp:Button ID="btn_Create_Option" runat="server" Text="Create Option" /></td> </tr> </table>\[/code\]and i have tried this one but unable to get values\[code\]Try Dim DB As New SQLDBDataContext Dim NGUID As New System.Guid(HF_QidOpt.Value.ToString) Dim boxes As TextBox() = New TextBox() {txt_OptText, txt_OptText2, txt_OptText3, txt_OptText4, txt_OptDesc, txt_OptDesc2, txt_OptDesc3, txt_OptDesc4} For Each t As TextBox In boxes If t IsNot Nothing Then Dim CO As New Question_Option With CO .UID = System.Guid.NewGuid .Question_ID = NGUID .Option_Text = 'How to get value of txt_OptText, txt_OptText2, txt_OptText3, txt_OptText4' .Option_Description = 'How to get value of txt_OptDesc, txt_OptDesc2, txt_OptDesc3, txt_OptDesc4' End With DB.Question_Options.InsertOnSubmit(CO) End If Next DB.SubmitChanges() MV_Default.SetActiveView(V_Success) Catch ex As Exception lbl_Failure.Text = ex.Message MV_Default.SetActiveView(V_Failure)\[/code\]End Try
 
Back
Top