|
Hi
In the code below, I'm looping through all the items in dtPackBom2 and for each item I then loop through dtExclusions. If the item in dtPackBom2 exists in dtExclusions then I delete it from dtPackBom2.
What happens is that even though the loop is
For BomRow As Integer = 0 To Me.dtPackBom2.Rows.Count - 1
after you delete a row, I get an exception saying there is no row at position xxx. I then tried adding the row Me.dtPackBom2.AcceptChanges() after I delete a row, hoping that dtPackBom2.Rows.Count will now see the new reduced number of rows but I still get the same exception.
It seems to work if I put: If BomRow = Me.dtPackBom2.Rows.Count - 1 Then Exit For
For BomRow As Integer = 0 To Me.dtPackBom2.Rows.Count - 1
If BomRow = Me.dtPackBom2.Rows.Count - 1 Then Exit For
For i As Integer = 0 To Me.dtExclusions.Rows.Count - 1
If Me.dtPackBom2.Rows(BomRow).Item(2) = Me.dtExclusions.Rows(i).Item(0) Then
Me.dtPackBom2.Rows(BomRow).Delete()
Me.dtPackBom2.AcceptChanges()
Exit For
End If
Next 'i
Next 'BomRow
WHY IS THIS HAPPENING. SURELY THE EXPRESSION Me.dtPackBom2.Rows.Count - 1 IS EVALUATED EACH TIME THE LOOP IS EXECUTED?
IS THERE A BETTER WAY TO DO THIS?
|
|
|
|
|
Try:
For BomRow As Integer = Me.dtPackBom2.Rows.Count-1 to 0 Step -1
This will count backwards through your rows.
|
|
|
|
|
RichardBerry wrote: SURELY THE EXPRESSION Me.dtPackBom2.Rows.Count - 1 IS EVALUATED EACH TIME THE LOOP IS EXECUTED?
Don't count on it. If you're removing items from a list, it's better to start at the end and work your way back to 0. The way you're doing it now, you'll skip items in the list when you remove one. Say you have 5 items in your list, indexed 0 to 4, and you're going to end up removing item 2:
Index Items
----- -----
0 "This"
1 "is"
2 "was"
3 "a"
4 "test"
Your counter, BomRow, has the value of 2 when you make a check and decide that you want to remove the item at that index. Now, after you remove the item, the Items.Count now says 4. Great! Who cares... You're array now looks like this after you remove the item, but BEFORE you get to the Next statement.
Index Items
----- -----
0 "This"
1 "is"
2 "a"
3 "test"
You finally reach the Next statement and increment BomRow. It's now 3, BUT since the items have moved down the list, you're not checking the item that just got moved to position 2 in the index! You've just skipped an item!
It's better to start at the end of the array and work your way back to 0. That way, you won't be skipping any items, no matter how many items you had to start with and how many you remove in each iteration of the loop.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thank you Dave!!!!!!!!
That explains a lot of my problems when I see it that way.
|
|
|
|
|
i am trying to read a number from an access table check it and use it to control access to another page.
this is the code snippet where i think the problem is and the feedback i'm getting is saying this "Data type mismatch in criteria expression" - referring to the highlighted line of code below.
Dim PinNumber As String
PinNumber = "SELECT DISTINCT Pin FROM Accounts WHERE Pin='" & Me.tbPin.Text & "'AND AccountID = '" & Me.tbID.Text & "'"
comm.CommandText = PinNumber 'the variable is declared as a command
dr = comm.ExecuteReader 'gives the variable a value
If dr.Read() Then 'if the entry is correct (readable)
Form2.Show() 'show the index varibale (form)
Me.Close() 'close the current form
Else 'if the entry is incorrect
MessageBox.Show("Invalid Pin, please try again") 'displays error message
tbPin.Clear() 'clears the managerid
tbID.Clear()
End If
|
|
|
|
|
You appear to be doing no validation before injecting the values from the user interface into the SQL. An invalid input could be causing problems. It could also be used by a malicious person in order to damage the database.
See SQL Injection Attacks and Tips on How To Prevent Them[^]
|
|
|
|
|
peteyshrew wrote: & Me.tbPin.Text & "'AND AccountID = '"
Don't you need a space before the AND. I.e. "' AND AccountID...
|
|
|
|
|
What he needs is to parameterise the query.
|
|
|
|
|
RichardBerry wrote: Don't you need a space before the AND. I.e. "' AND AccountID...
No... the ' (single quote) acts as a delimiter too, and this will work, provided that PIN is a text type field.
|
|
|
|
|
ChandraRam wrote: and this will work, provided that PIN is a text type field.
And so long as the user doesn't type anything dodgy in to the PIN TextBox because as soon as that happens all hell breaks loose and the company finds that their database is compromised.
|
|
|
|
|
Hi, Im using crystal reports integrated with visual studio.net 2005. Currently, i have a 3 page report, it shows perfectly in the crystal report viewer, but it has problems when i export it.
When i export to word format, only the first page is exported along with a blank page and when i export to PDF format, total 6 pages are exported 3 being the report pages and 3 being blank pages after each report page. I require to export to word format but i have no idea wats causing this problem....any help will b greatly appreciated...its urgent!
|
|
|
|
|
hi...
how to retrive data from buffer
once the data is placed displayed on form
the data has to be deleted from the buffer
that means
once the data is displayed from the buffer ..the buffer should clear the displayed data and the next data has to be stored in that.....
this process must continue like that.....
thanks & Regards
|
|
|
|
|
What interface are you using to read the buffer? Are you using the SerialPort class in the .NET framework or are you using P/Invokes to the Windows API?
If you're using the SerialPort class, the buffer is automatically cleared once you call any of the Read() methods - there are several of them for reading to the end of the available data, reading a line, reading a character, reading a byte, etc.
------------
Cheers,
Patrick
|
|
|
|
|
Help me now!
I want to know the face detection algorithm and face recognization. Nobody known to help me.
Thank so much.
My email: leminhtuan75@yahoo.com
Học, học nữa, học mãi.
V.I.Lê Nin.
|
|
|
|
|
Please do not spam the entire site. Type your question in to google instead.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi
I really dont know whether this is the right forum - but here goes -
I am currently searching for a end user customizable reporting tool.
A reporting tool that allows the end users (users of my developed application) to design/change their own reports.
This tool should also allow the programmer some customizability to control the data sources, login information and so on.
This reporting tool needs to work with VB/C#.Net
Currently, I am looking at Sharp Reports (Perpetuum.com) and List & Label.
List & Label seems over complicated while Sharp Reports seems OK.
Can you guys please suggest some more options for this type of application?
I have concluded that writing this type of application on your own would be a tedious job and a project in itself. Is this conclusion correct?
I think that Crystal Reports does not have such a functionality - am I right?
Thanks.
-- modified at 2:04 Monday 23rd April, 2007
Shreekar
|
|
|
|
|
hi guys, what is the equivalent of this lines of codes in VB.Net
1.SendKeys {HOME} + {END}
Don't block the drive way of all the newbies in programming.
|
|
|
|
|
In VB2005 it would be like this: My.Computer.Keyboard.SendKeys(Keys.Home & Keys.End)
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
I was attempting to use a service with a filewatcher. I soon realized that the service ran as 'localservice'. Thus it had none of the rights of the logged on user. Nor could it access the users 'Local Data' path.
I also discovered that I couldn't run another VB.NET app from the service, cause the app was considered part of the service, making it impossible to run a normal app with a user interface. I began to understand that the service would not be able to access SQL - cause it's not a registered user.
Can anyone recommend a good book or examples of how to code services so they can impersonate the logged on user?
This seems so restrictive - what's the worth of a service to an everyday programmer?
My workaround is a system tray app, which works fine.
|
|
|
|
|
dBrong wrote: My workaround is a system tray app, which works fine.
This app wont start automatically, i guess.
dBrong wrote: what's the worth of a service to an everyday programmer?
Anything that needs to be done in background, generally uses services as an application type. For example, Virus checking / removing softwares.
dBrong wrote: so they can impersonate the logged on user
Just change the local service account with the User account. This can be done using the service installer. Each time this service starts now, it will use the credentials provided by the user (User credentials). The credentials are asked for when service is installed.
Hope this solves your most problems ?
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
coolestCoder
|
|
|
|
|
dBrong wrote: This seems so restrictive - what's the worth of a service to an everyday programmer?
Services are normally written as servers, like a web server, ftp server, smtp, ... They normally don't impersonate users unless there is a specific permission they need. In that case, a normal user account is created and the permissions on it specifically setup to give the service the rights it needs and no more.
If your app doesn't do anything until a user is logged in, it should be rewritten as a normal application, but one that puts it's interface in the system tray (NotifyIcon class). It'll normally launch from the Run key in the registry or from the All User\Startup folder. This way, it'll always run in the security context of the user that's logged in and you don't have to worry about user switching and impersonation.
dBrong wrote: I soon realized that the service ran as 'localservice'. Thus it had none of the rights of the logged on user. Nor could it access the users 'Local Data' path.
True. LocalSystem is the default account that a windows service runs under, having no rights to any network resources.
dBrong wrote: also discovered that I couldn't run another VB.NET app from the service, cause the app was considered part of the service, making it impossible to run a normal app with a user interface.
Services run under a different desktop thatn what the user sees, by default. So any forms or interface elements that you put up don't get shown on the visible desktop. They get shown on a sdesktop that you cannot see! There is a switch in the Services manager that allows a service using the LocalSystem account to show it's interface on the desktop though. You just need to get the Properties page of your service, go to the LogOn tab and you'll see it.
dBrong wrote: I began to understand that the service would not be able to access SQL - cause it's not a registered user.
Not true. It can't access an SQL database where the connection string is using "Trusted Connection", but it can if the login credentials are supplied for a valid SQL Server account. Access databases are file-based, so any access to one of these requires filesystem rights. If the database is stored on the network, you run into the first problem above. LocalSystem doesn't have network rights, so youre service has to use a user account specifically setup for it.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
i am using vb.net 2003 and using datagrid to show my records in my table. after a month i switch to vb.net 2005 and i have problem in the event of double_click of datagridview of vb.net 2005.
this is my code in double_click event of vb.net 2003 using datagrid
txt1.text=datagrid1.item(datagrid1.currentrowindex,0).tostring
this is my code in double_click event of vb.net 2005 using datagridview
txt1.text=datagridview1.item(datagridview1.currentrow.index,0).tostring
my problem is. when i double click my datagridview in vb.net 2005 the value of my textbox is this "DataGridViewTextBoxCell { ColumnIndex=0, RowIndex=0 }"
but in vb.net 2003 is ok. i mean what ever the value of my index 0 in my table that is the value of my textbox. any idea why in vb.net 2005 give me an output like that. thx in advance
Don't block the drive way of all the newbies in programming.
|
|
|
|
|
The DataGridView is a completely different animal from the old DataGrid in 2003. The Items collection in the DGV returns, as you've found out, a DatGridViewTextBoxCell object, or whatever object type the column is, not the data inside it!
To get at the value that's displayed in the cell, you can use one of two things. Either the Value property of the returned DataGridViewTextBoxCell, or the FormattedValue (as displayed in the grid).
text1.text = dgv1.item(dgv1.currentrow.index,0).Value
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Along those lines, could you help me out with this code that isn't working the way I want it to.
I am trying to insert new row(s) into a datagridview called "CustSalesOpportunityLineDataGridView" (that is databound to a table called "custsalesopportunityline" in a master-detail form that contains includes the header info as well).
I have also created a generic product selection form that contains a datagridview called "ArticleDataGridView" that displays all the info and contains the filters that users need to efficiently search and filter out products. The dataset for the "ArticleDataGridView" is based on a view that I have created in the database.
On the "ArticleDataGridView" I have created a column called "Select_Article" that is a DataGridViewCheckBoxColumn. (false value = 0, indeterminate = 0, true =1). If the users want to add a particular product to the SalesOpportunityLine datagridview they should be able to check the checkbox for each desired row and then click the AddAndContinueButton. The Select_Article checkbox column is the leftmost column of the datagridview.
For each product that they have selected in the articledatagridview a new row in the "CustSalesOpportunityLineDataGridView" should be created and displayed as well as the articleID, name and Salesopportunityheaderid.
Where am I going wrong with the code below? Based on the error messages I am getting I don't think it is reading from the correct column.
Private Sub AddAndContinueButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddAndContinueButton.Click<br />
<br />
For Each dgvRow As DataGridViewRow In Me.ArticleDataGridView.SelectedRows<br />
If Me.ArticleDataGridView.Item(ArticleDataGridView.CurrentRow.Index, 1).Value = 1 Then<br />
Dim dt As DataTable = Me.SalesOpportunity.Tables("custsalesopportunityline")<br />
Dim dtRow As DataRow = dt.NewRow()<br />
dtRow("Salesopportunityheaderid") = NewSalesOpportunity.SalesoppHeaderID<br />
dtRow("articleid") = dgvRow.Cells("ArticleIdDataGridViewTextBoxColumn").Value<br />
dtRow("work_articlename") = dgvRow.Cells("ProduktnavnDataGridViewTextBoxColumn").Value<br />
dt.Rows.Add(dtRow)<br />
<br />
End If<br />
Next<br />
<br />
End Sub
|
|
|
|
|
thx for the Info Dave.
Don't block the drive way of all the newbies in programming.
|
|
|
|