Hello Everybody. I am doing a windows appln in vb.net. I have a button in my form. When i click the button, textboxes are added dynamically to the form. For 1st click 4 textboxes are added. When clicked again, again the textboxes are added once again...Now i need to save the data from the textboxes to database. Pls anyone help me with that. Here is my coding.
Dim value1 As String = "" Dim value2 As String = "" Dim value3 As String = "" Dim value4 As String = "" Dim i As Integer For i = 0 To FlowLayoutPanel1.Controls.Count - 1 Select Case FlowLayoutPanel1.Controls(i).Name
Case "TextBox1" value1 = FlowLayoutPanel1.Controls(i).Text
Case "TextBox2" value2 = FlowLayoutPanel1.Controls(i).Text
Case "TextBox3" value3 = FlowLayoutPanel1.Controls(i).Text
Case "TextBox4" value4 = FlowLayoutPanel1.Controls(i).Text End Select Next i Dim strsql As String strsql = "insert into stud values ('" & value1 & "','" & value2 & "','" & value3 & "','" & value4 & "')"
Only the text in the first four textboxes is getting aded to the database.What about the others
|
| Author: Pannalal Sinha 07 Nov 2009 | Member Level: Gold | Rating:  Points: 2 |
Why are you adding the textboxes on button click. I think you should add those in the page load, then u need not add them again and again.
After inserting the values in the query, clear the textbox values and use freshly for next button click.
Thanks Panna
|
| Author: sirisha 08 Nov 2009 | Member Level: Silver | Rating:  Points: 2 |
Thanku for ur reply Sinha But i dont want to add the textboxes in form load. If the user wants to add 10 records , he wants to add them at a time. He doesnot want to add them one by one every time clicking the save button. Can u help me in that way.
|
| Author: pradeep kumar reddy 09 Nov 2009 | Member Level: Silver | Rating:  Points: 2 |
hi, yeah you are correct if we write code in page load it creates text boxes each time dynamically. to avoid this we have to create these text boxes in page load in the condition "if(!ispostback)" it means if it already postback means it will not execute again. these will remain as it is.
|