|
|
Whenever you're removing items from a collection within a For loop, you should start and the end of the collection and work backwards. Otherwise, you end up skipping every element following a removed item.
For i As Integer = dt_grid1.Rows.Count - 1 To 0 Step -1
...
Next
You'll also need to specify the row you're looking at when you read the column value:
If dt_grid1.Rows(i)("BarCode").ToString() = dtserialleft.Rows(j)("SerialNo").ToString() Then
found = True
Exit For
End If
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
First a quick description of the problem. A piece of software written in VB handles a lot of stuff. 6-8 active users at a time. One module deals with planning and got 2-3 users which use this.
Up until recently only one user was actively using this module but structural changes within the workforce has changed this.
This has brought on a problem where changes to the planning seems to disappear for those that plan. My problem when fixing this is that I'm not 100% exactly what does what so I want to create a solution that is as small and clean as possible to fix the issues as we are moving to another system sometime within the next 4month-2years.
The module queries an SQLDatabase and then renders the used table using some fancy VB6 graphics. Changes are made and then saved.
When a save is made a lot of rows are deleted and then remade with the new data. I think the problem might be that what is deleted isn't just those entries that are changed but a large chunks of rows fit inside the selection criteria. This means that if 50 rows are selected and 5 changed by user A which saves if user A got the data before user B made it's changes user B's changes are overwritten if their are included inside the selection criteria.
Those who use this module swear that they use the reload function correctly to make sure they got the latest data and then swiftly make their changes and saves and that in order to avoid the problem they make sure only one is editing at the time but you know... ...users.
One of the things I'm working on adding is a check where I look if someone else has changed the data before saving and compare. If user A's and user B's changes doesn't overlap I will merge these instead of overwriting everything and if there are conflicts I will promt the user as to which change they want to use.
This should fix it because even if the query selection returns the same set of data in a majority of cases they are working on different parts of this set.
That's what I've been doing so far and will implement. Even if it doesn't fit 100% what they want this will be what they get.
That should hopefully describe the current situation. Since they actually try to avoid working at the same time my boss also suggested to add a lock/semaphore to enforce the idea that only one user can edit the data. And I just wanted to get some input on a quick way of doing it.
I was thinking of adding three controls/buttons and a status window. Status window will show if and who is currently editing if its locked or if its free to take the position as editor.
Lock and unlock button as well as force unlock.
Super easy to add this as well as the logic behind this that I figured.
I'll add a table which I plan to use as my lock. This will contain one entry which says if the table should be locked. If so, who is currently owning the lock and time of locking.
Add some queries to the buttons and a few other places in the code and bam, only one user can edit.
I'm interesting in viewpoints on my solution as well as other ways to do it. What I like with this is the simplicity to implement for me and simple way of making sure that the users always can force an unlock if something should happen.
|
|
|
|
|
The buttons sound like a disaster waiting to happen. Give users a "Force Unlock" button and you're right back where you started.
Do some reading up on locking techniques[^]
If you can't get rid of the VB6 stuff altogether you could also consider a COM dll (written in a .NET language) that you could use to leverage SQL notification services - more info at Query Notification using SqlDependency and SqlCacheDependency[^]
|
|
|
|
|
Will read up on locking.
Seems like locking depends on using transactions which this system doesn't use at all. The entire thing is a jumble that I've inherited and I'm the third generation now I think.
Won't apply it now as I went with the dirties quickest solution that is good enough for now.
|
|
|
|
|
Reading through the description of the system it is quite obvious that it is not suited to multiple access - particularly the deletion and re-insertion of data rather than updates.
There is no manner in which you can 'fix' things that will not cause you a world of pain in the future.
I would say you have 2 options:
(1)Rewrite the underlying database update mechanism so that it does not makes use of deletions and inserts.
(2)Leave things as they are an only allow one user to access the application at a time.
Even if you do go with option (1) there is no solution to the update conflict issue.
Quite simply if two users grab the same record, the person who makes the second update wins - there is no way around this no matter how much clever code you write.
Given that the best minds in computer science have not yet solved this problem there is little chance that you or I will.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
I went with a simple lock that relies a lot on the fact that the users use it the correct way but there are only 3 of them and I only need to reduce the amount of conflicts. Time constraints where I've got to priorities what I do kind of forced me to do what I found the easiest atm.
Now the user wont be able to edit unless they own the lock so to speak and will be prompted to do this and I've gone over all the available functions and added checks to verify correct usage.
Hopefully this will reduce the amount of conflicts. Their problem seems to be compounded by stress when a conflict happens because of their time constraints. If there is one they usually make more shortly there after.
At this point rewriting the entire updating mechanism isn't interesting because in the not so far off future we will change systems and my work now is more to make sure it keeps afloat until that time.
|
|
|
|
|
What happens if a user is booted out of the system while the have the lock?
I guess you have to go in and manually unlock the row(s).Member 11683251 wrote: relies a lot on the fact that the users use it the correct way Good luck with that because in my experience systems need to be written to either guide users or to block them from breaking a system. Relying on users to do things 'the correct way' will lead to the sort of trouble you currently find yourself in.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
The guy that worked here before me had basically given up on user interactions. One part of the system deals with users reporting produced goods and despite numerous checks and controls people still managed to mess it up. One common mistake was that people wrote their userid where you should put the number of goods produced so headed a comparison with their userid was and if it matched with reported goods prompted user to answer if they wanted to proceed. People ended up just clicking yes anyway so instead he just added a big nope can do if they tried to do it.
But I'll put my faith in to that these three can manage a few months.
There is a force unlock available to avoid that and even if that doesn't work this system isn't very safe when it comes to credentials so they could just solve it by exiting and entering again and say that they are the person that owns the lock.
|
|
|
|
|
If I was in your position I would do this:
I would create a separate application that allows me to unlock specific rows - a force unlock on all rows could cause issues if some of those rows still need to be locked.
It sounds like you have inherited something of a nightmare to support.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
It can be a bit of a headache at some times. No documentation at all. The way it's build is at least fairly compartmentalized and everything follows the same flow but certain parts like this module is a bit more complex. A lot of time gets eaten up just by understanding how things are supposed to work.
It doesn't help that I got a lot of duties that are quite spread out which means that when something pops up in a part which I haven't familiarized myself with it's so much harder.
And lastly the entire system is a classic case of a program or suit of programs in this case which has grown in scope as different needs has come up.
For example there are several types of "orders" which are stored in different tables. There are customer orders, which is the entire order of what they want and how much, shipping orders which specify when and what things are to be delivered, these are related to the customer order. Then we have at least two types of internal productions order which are there to specify when we need to produce what. All complete with poor name conventions and lack of documentation.
The upside is that people see me as some sort of magician when there is a problem and quickly figures it out.
I'm a good problem solver but average programmer with zero database experience before I started working here and originally was hired to program robots.
|
|
|
|
|
Member 11683251 wrote: I started working here and originally was hired to program robots Ah, in which case you need one of these[^] to fix all your user/database related problems.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
Hi, I am using Vb.net 2010. I have 2 data tables, which have different set of columns. I would like to copy the rows from one data table to another . How to loop through each of the rows in the first data table and set the values in the second data table. Thanks
|
|
|
|
|
One possibility is that you create a LINQ query that queries the source datatable and fetches the columns that match in the target datatable. When looping through the results, add a new row as an object array into the target table or create a new table and use that.
Have a look at Creating a DataTable From a Query (LINQ to DataSet)[^]
|
|
|
|
|
whats the code for command buttom to call the report with crystal report there are have 2 details in 1 report with database acces in vb6..pls help thks
|
|
|
|
|
|
It requires a lot of code and no one can or will just write it for you. Do you have a more specific question?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I'm using the example provided earlier in a previous post of mine.
I want to convert this sql linq statement into a queryable, so I can adjust the take and skip,
But I can't figure out how to Join and do Multiple contains using IQueryable.
So I wrote this which works, but now I only want to take the data I need, and not the whole table that matches. I thought I needed to go IQueryable for the Take and Skip, not being to add that to the code below. If I'm wrong, please let me know.
Dim p_pageIndex as integer = 1
Dim p_pageOffset as integer = 10
Dim p_SearchQuery as String = "Kneepads"
Using context As New DBContext()
Dim pResults = _
(
From pi In context.ProductInfo
Join pik In context.ProductInfo_Keywords On pik.ProductID Equals pi.ProductID
Where pik.Keywords.Contains(p_SearchQuery.Trim) _
Or pik.Stream.Contains(p_SearchQuery.Trim) _
Or pi.PartNumber.Contains(p_SearchQuery.Trim)
Order By pi.PartNumber, pi.SDescription, pi.Description Descending
Select
pi.ProductID,
pi.CategoryID,
pi.SubCategoryID,
pi.SDescription,
pi.Description,
pi.Thumbnail,
pi.PartNumber,
pi.Price
)
In the example above, I have multiple contains from 2 tables that are Joined, I can't figure out the wording for the Join or multiple contains. the multiple OrderBy's was from a previous version in TSQL where I used ORDER By RANK
Dim context As New DBContext()
Dim items As IQueryable(Of PRODUCTINFO) = context.ProductInfo
'Sort
items = items.OrderByDescending(Function(m) m.PartNumber).OrderByDescending(Function(m) m.SDescription).OrderByDescending(Function(m) m.Description)
'Filter by Rank
items = items.Where(Function(m) m.PartNumber.Contains(p_SearchQuery))
'Get a Single Page of Data
If (p_pageIndex = 1) Then
items = items.Take(p_pageOffset)
Else
items = items.Skip((p_pageIndex - 1) * p_pageOffset).Take(p_pageOffset)
End If
pResults = _
items.AsEnumerable().Select(Function(pi) New searchIndex With
{
pi.ProductID,
pi.CategoryID,
pi.SubCategoryID,
pi.SDescription,
pi.Description,
pi.Thumbnail,
pi.PartNumber,
pi.Price
}
)
|
|
|
|
|
How to Use Tessnet2 Library[^]
The above code is easy to use... and works well.
Add the tessnet2.dll to the references, add the "tessdata" folder to your project, insert the VB code in a Sub... done.
BUT TESSNET2 IS DEPRECATED.
Someone knows where to find as easy to use VB.net code and a tessnet302.dll working with Tesseract 3.02??
|
|
|
|
|
ezio2000 wrote: BUT TESSNET2 IS DEPRECATED. Where does it state that? If it is deprecated, then there will also be a recommended alternative.
Looks more like there's a new version of Tesseract, and not of the Tessnet library.
ezio2000 wrote: Someone knows where to find as easy to use VB.net code and a tessnet302.dll
working with Tesseract 3.02?? Google never heard of the file. Are you sure there is a new library for the new version of the product?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Please help me to convert the C# coding below to VB.Net.
Thank you
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
var XML = "XML=<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<SMS>\n" +
"<operations>\n" +
"<operation>SEND</operation>\n" +
"</operations>\n" +
"<authentification>\n" +
"<username></username>\n" +
"<password></password>\n" +
"</authentification>\n" +
"<message>\n" +
"<sender>SMS</sender>\n" +
"<text>Test message [UTF-8]</text>\n" +
"</message>\n" +
"<numbers>\n" +
"<number messageID=\"msg11\">380972920000</number>\n" +
"</numbers>\n" +
"</SMS>\n";
HttpWebRequest request = WebRequest.Create("http://atompark.com/members/sms/xml.php") as HttpWebRequest;
request.Method = "Post";
request.ContentType = "application/x-www-form-urlencoded";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(XML);
request.ContentLength = data.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(data, 0, data.Length);
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
if (response.StatusCode != HttpStatusCode.OK)
throw new Exception(String.Format(
"Server error (HTTP {0}: {1}).",
response.StatusCode,
response.StatusDescription));
StreamReader reader = new StreamReader(response.GetResponseStream());
Console.WriteLine(reader.ReadToEnd());
Console.ReadKey();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.ReadKey();
}
}
}
}
|
|
|
|
|
We're not going to do your work for you.
Just Google for "Convert C# to VB.NET" and you'll come up with a bunch of online conversion tools.
|
|
|
|
|
Please I'm using vb.net 2013 and Microsoft office 2013. The below code is able to display the datagridview
into excel 2007. But the code does not display onto excel 2013 and no error gets reported. I suspect the
excel 2013 format could be the cause but i do not know how to go about it.
<pre lang="vb"
Dim ExcelSheet As Object
Dim i As Integer
Dim j As Integer
'create object of excel
ExcelApp = CreateObject("Excel.Application")
ExcelBook = ExcelApp.WorkBooks.Add
ExcelSheet = ExcelBook.WorkSheets(1)
With ExcelSheet
For i = 1 To Me.DataGridViewGCL.RowCount
.cells(i, 1) = Me.DataGridViewGCL.Rows(i - 1).Cells("GclNo").Value
For j = 1 To DataGridViewGCL.Columns.Count - 1
.cells(i, j + 1) = DataGridViewGCL.Rows(i - 1).Cells(j).Value
Next
Next
End With
ExcelApp.Visible = True
'
ExcelSheet = Nothing
ExcelBook = Nothing
ExcelApp = Nothing
></pre>
|
|
|
|
|
Which version of Office do your interop-dll's target? If you are using the files from Office 2007, then it probably will not be able to read a 2013 file, since Excel 2013 did not exist at that time.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|