-
Mar 17th, 2018, 06:38 PM
#1
Thread Starter
Lively Member
How to insert textbox on button click and save data in all the textboxes in db VB.net
Last edited by astrid22; Mar 17th, 2018 at 07:03 PM.
Reason: code
-
Mar 17th, 2018, 07:20 PM
#2
Re: How to insert textbox on button click and save data in all the textboxes in db VB
What do you want to save to the database, and how would it look? I assume you want to save the contents of the textboxes, but you could also be talking about saving the number of textboxes, or something else, so you might as well clarify.
As to the database, as long as you are only talking about a maximum of 9, you might have nine fields in a table in the DB. When you have a textbox, you could write data for that field, and when there isn't a textbox, you would write a null for that field. That would be one way to do it, but it wouldn't scale well if you have more than just a few textboxes.
The alternative would be to have two tables in the database. One record would be the master record. I have no idea what would be in that record, and maybe it doesn't even need to exist. In the other table, you'd want one record per textbox. If there is no need for the master record, then the other table could just have one column with a shared value and one column for the value of the textbox.
As I write that, I realize there are several other alternatives that would also make sense, depending entirely on what you want to store, what else goes with it, and how it will be used.
My usual boring signature: Nothing
-
Mar 17th, 2018, 07:29 PM
#3
Thread Starter
Lively Member
Re: How to insert textbox on button click and save data in all the textboxes in db VB
Sorry I forgot to clarify
I will be putting data in the textboxes and save the data into the database.
For example, the question is list the names of your favorite friends. Then there's this txtNumOfT textbox where I will input the number of textboxes I need for example 5 textboxes, click on insert button then it will insert 5 textboxes. Then I will input the names of my friends in those 5 textboxes. After that I will click on save to database button to save the question and the names of my friends into the database.
-
Mar 17th, 2018, 09:28 PM
#4
Re: How to insert textbox on button click and save data in all the textboxes in db VB
Then why is it limited to 9? I've heard that there is a limit on how many close friends we can have, but still, it seems like your number might go over 9.
You might consider a FlowLayoutPanel rather than the TableLayoutPanel, and just allowing the number to grow as needed. Another alternative would make working with a database even easier, but it would look totally different, so you might not find it suitable. That other alternative would be to use a DataGridView tied to a Datatable. You'd still be able to add items, and they'd end up in a datatable, which would be easier to use for interacting with a database. In fact, even if you prefer the layout panel you have, you might find it easiest to then put the items into a datatable:
Code:
Dim myTable as New Datatable
myTable.Columns.Add("GiveTheColumnANameHere",GetType(String))
Then you can add rows pretty easily:
Code:
Dim nr As DataRow=myTable.NewRow
myTable.Rows.Add(nr)
They the datatable could write to a database table pretty easily. However, this isn't a great design. After all, there's no checking for duplicates, or anything of the sort. Still, there is plenty of information about reading/writing a datatable to a database, so it would get you closer as a general design.
My usual boring signature: Nothing
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|