Create N rows in database

tiffany

Well-known member
Joined
Aug 7, 2005
Messages
57
Programming Experience
1-3
Is there any possible codes when example i need to create 4 rooms and i enter 4. In the database it will automactically create 4 rows of records once i clicked submit button. Any sample codes? Thankx.

Regrads,
tiffany
 
do you want to pass some data into certain DB or just want to create an empty rows and UPADATE it later?

However, you could pass the same empty string to the table say table1

for i = 0 to 4
strSQL = "INSERT INTO Table1 (column1) VALUES ('" & String.Empty & "')
cmd = new oledbcommand(strSQL, myConnection)
cmd.ExecuteNonQuery
next

just be sure that field column1 has enabled allow zero lenght to YES (if you work with MS ACCESS)

Cheers ;)
 
Hi kulrom, I want to pass some data in the MS acees db to the new rows. If i use this code, what if i need to add in 5 rooms instead of 4 rooms?

for i = 0 to 4
strSQL = "INSERT INTO Table1 (column1) VALUES ('" & String.Empty & "')
cmd = new oledbcommand(strSQL, myConnection)
cmd.ExecuteNonQuery
next

Rgds,
tiffany
 
If you want to create a record with data then you have to put that data into the rows, so obviously you have to create each row. You could write a function that takes an array or collection of values, then creates a row for each element or item and inserts it.
 
say you want to pass records from listview

Dim lvitem as ListViewItem
VB.NET:
For each lvitem in listview1.items
strSQL = "INSERT INTO Table1 (column1, column2) VALUES ( " & _
"'" & lvitem.Subitems(0).Text & "', '" & lvitem.Subitems(0).Text & "')"
cmd = new oledbcommand(strSQL, myConnection)
cmd.ExecuteNonQuery
Next

btw, :D i know vb.net is zero based lang and it was technical error :)

Cheers ;)
 
So what if i want to pass records from textbox? Like example i enter 3 in the textbox and in db it will automantically create three more rows. I'm a newbie..pls help! Btw i'm using asp.net.
 
Last edited:
Hi, i had solved the problem. But i had another problem. How is the code like if the database had exceed20 and it won't allow any entry in?


Rdgs,
tiffany
 
Back
Top