|
-
Jan 23rd, 2011, 02:34 PM
#1
Thread Starter
New Member
Add textbox value to datatable multiple times
Here is my code:
HTML Code:
Dim num As Integer
num = Me.txtCopies.Text
If num = 0 Then
MessageBox.Show("The number of copies cannot be under 1.", "Popcorn Movie Rentals Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
Me.txtCopies.Select()
Me.txtCopies.Focus()
Else
Me.PmrDataSet.Movies.Rows.Add(movie)
End If
My textbox (txtCopies) default value is 1 so naturally, as it is coded above, the datarow is added once into the Movies Table. But what I need to know is how to code if the txtCopies field has a greater integer value.
Thx for all the help in advance!
LadySylvia
-
Jan 23rd, 2011, 04:14 PM
#2
Re: Add textbox value to datatable multiple times
try this:
vb Code:
Dim num As Integer
integer.tryparse(Me.txtCopies.Text, num)
If num = 0 Then
MessageBox.Show("The number of copies cannot be under 1.", "Popcorn Movie Rentals Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
Me.txtCopies.Select()
Me.txtCopies.Focus()
Else
for x as integer = 1 to num
Me.PmrDataSet.Movies.Rows.Add(movie)
next
End If
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 24th, 2011, 01:35 PM
#3
Thread Starter
New Member
Re: Add textbox value to datatable multiple times
Unfortunately no, it didn't work, here's the error message:
ArgumentException was unhandled
This row already belongs to this table.
No idea what that means!
-
Jan 24th, 2011, 01:44 PM
#4
Re: Add textbox value to datatable multiple times
what is movie? is it a datarow?
try movie.clone instead of movie
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 24th, 2011, 01:50 PM
#5
Thread Starter
New Member
Re: Add textbox value to datatable multiple times
yes, movie is a datarow.
i was told to arrange the loop so that the row is only handled once, then found and copied after.
the loop is written after the code i posted above.
think that would work?
here's the current loop:
vb Code:
Me.MoviesTableAdapter.Update(Me.PmrDataSet) Dim findmovies As DataRow Me.PmrDataSet.Members.PrimaryKey = New DataColumn() {Me.PmrDataSet.Movies.Columns("Title")} findmovies = Me.PmrDataSet.Members.Rows.Find(Me.txtTitle.Text) For Each findmovies In Me.PmrDataSet.Movies.Rows If findmovies.Item("Title") = Me.txtTitle.Text Then movieIdsfrm.lbxHidden.Items.Add(findmovies.Item("MovieId")) End If Next movieIdsfrm.Show()
-
Jan 24th, 2011, 01:53 PM
#6
Re: Add textbox value to datatable multiple times
why do you need to add multiples of the same datarow to your datatable?
looking at your code in post#5 it looks like you want to add the movie MovieId to a listbox?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 24th, 2011, 01:59 PM
#7
Re: Add textbox value to datatable multiple times
try this:
vb Code:
Me.MoviesTableAdapter.Update(Me.PmrDataSet)
Dim findmovies As DataRow
Me.PmrDataSet.Members.PrimaryKey = New DataColumn() {Me.PmrDataSet.Movies.Columns("Title")}
findmovies = Me.PmrDataSet.Members.Rows.Find(Me.txtTitle.Text)
movieIdsfrm.Show()
For Each movie In findmovies
If movie.Item("Title") = Me.txtTitle.Text Then
movieIdsfrm.lbxHidden.Items.Add(movie.Item("MovieId"))
End If
Next
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
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
|