In the properties window make sure CheckedOnClick equals true for each of the menu items.

Add to your menu item events:

mnuMexico.Checked = Not mnuUnitedStates.Checked
End Sub

mnuUnitedStates.Checked = Not mnuMexico.Checked
End Sub

Opps just re-read your post. My example will return how many records were updated; not give you that number before hand. I would suggest using stored procedures, this way there tested first and you wont forget to add anything to your string.

intTotalRecordsUpdated = command.ExecuteNonQuery()

Here is an example written in a console app showing the calculated salary for each day of the pay period. The final result is all that is needed in your app but its good to at least follow along what is happening with each itteration of the loop.

Module Module1
Sub Main()

    Console.WriteLine("Total Salary: {0}", GetSalary(0.01D, 19).ToString("c"))

End Sub

Private Function GetSalary(ByVal decStartingAmount As Decimal, ByVal intTotalDaysWorked As Integer) As Decimal

    Dim decSalary As Decimal = 0

    For intDay As Integer = 1 To intTotalDaysWorked

        If intDay = 1 Then
            decSalary = decStartingAmount
            decSalary *= 2
        End If

        Console.WriteLine("Day #{0:00}){1}Salary: {2}" _
                          , intDay _
                          , ControlChars.Tab _
                          , decSalary.ToString("c"))
    Next intDay

    Return decSalary

End Function

End Module


If you use a NumericUpDown control it will save you some datatype conversions and validation and will limit users to only entering numeric values. For the calculation I would use a loop; passing the days worked and starting amount.

decPay = decStartingAmount

For intDay = 2 To intTotalDaysWorked
decPay *= 2
Next intDay

[QUOTE=adatapost;1148252][b]>will you provide some real good example on backgroundworker control in for doing some process in background.[/b]

Not the real question. [URL="

Theres a few books on the subject over on amazon

A little more detail about what isnt working would be helpful. Also you should properly declare instances of each for you want to create.

Private Sub LoadForm3( )

Dim frm As New Form3

End Sub

Wow did you even try looking up the answer for yourself before asking others to do it for you?

You need to clarify this and provide a bit more detail. Reading your post I have no clue what your trying to accomplish.

No need to code to keep validating texbox values. Just use a NumericUpDown control. It is essientially a textbox control that only allows numbers. Also you then wont need to keep converting your textbox values back & forth to a numeric datatype.

It is very bad programming to store images in a database. It is much better to instead store the file name and path to point to loading the files.

Images are much larger then text and will quickly accumalate the size of the database. Even if using very small resolution images, everytime you update any field within the same table that whole record is completly recopied (doubling in size) even without updating the actual image. Plus each time your create an index, it duplicates the size of the table. Additionally your using select * to constantly send all this data back and forth between the database and storing in memory.

Your IF statement is returning that message box if you have any records in your dataset table at all. Second your insert command is never even set to execute anything to the database. You really should start by learning how to step thru your code

It is important to note that a datagridview is only a means of displaying an underlying datasource. When working to manipulate that data you should work directly with that underlying source.

Unless the column you are searching happens to be the table primary key, using a dataview as Adapost suggests is probably the most efficient way of filtering a DataTable.

Yes you can and should use an ampersign instead of a plus sign.

With that said though, concatenating strings isn't the most efficient way to program. Although you may only be using one variable, every time you concatenate into that variable it is actually making a new variable in memory.

I wouldnt worry about it with something as small as you mention but something to keep in mind when using a lot of concatenation such as in a loop. It is much more memory efficient and faster to use a sting builder instead.

I have a process that does a lot of data manipulation and then prints a simple report directly to a printer. The overall priority is speed. Tens of thousands of records need to be scanned & processed individually so moving thru them quickly as possible is the goal.

Pseudo code

01) Scan Barcode
02) Fill DataSet from Sql Server
03) Manipulate data in dataset
04) Update data back to Sql Server
05) Print crystal report directly to printer; the dataset is the reports source
06) Clear dataset and start next record back at step one

The process if pretty complicated with a ton data manipulation and data coming from multiple sources but that part works super and in short all I am doing is scanning barcode, filling a dataset, passing it to a report and starting over.

Steps 1 to 4 are averaging one tenth of a second (0.01) to complete; great. Passing it to the report to print takes several seconds which is the problem. I thought I would resolve this by passing the dataset to the report print sub – allowing the print sub to run on a background thread – and moving on to processing the next record.

Dim m_ds As MyTypedDataSet

Sub ScanBarCode

   Fill DataSet
   Validate & Manipulate Data
   Call PrintReport
   Clear Dataset

End Sub

I have been attempting to add the PrintReport sub to process on a background thread. The problem though is the main thread blows right by to the next step and ...

Using database functionality you can read and write to an excel file without having to automate Excel as long as what you are writing following a consistent table structure. I definitely prefer this method it is very easy and doesnt require the user to even have Excel. However you do lose formatting options such as bolding cells. (ive been trying to find a way for the last month and havent been able to do so.)

You need to provide a bit more detail but I dont think there is any real need of using a timer just to update a status bar.

For example if your looping thru rows in a returned dataset or lines in a file, you want to start by simply setting the max value to your total count. Then within your loop increment each itteration by 1.

If you are unaware of count or how long something will take to process you can set the progress bar state to marquee which will give an non-stopping animation which you can deactivate when completed.

You can use ODBC to output a dataset or datatable directly to an excel file without the need of automating Excel itself or even requiring the user to have Excel installed. In this case, I would fill a datatable and bind it to your listbox and then export to the excel file.

This method is very easy and fast and doesnt require automating Excel in order to write the file. It doesnt even require the user to need Excel installed on there PC. However since your not actually using Excel, you do lose some functionality such as the ability to format cells in the worksheet (no bolding header lines, resizing columns etc)

I have already answered this with an example on the other board you posted the same question

You need to make a dynamic connection string. Meaning that you need a way to prompt the user (if the settings werent previously saved) to select the server & database they will be using and from there save your connection string.

There is so much to learn to working with databases and programming that I would suggest starting with a book to get a full overview. Ive been thru many books over the years and there are definitely more recent books published but one book in particular that is my favorite and specific to database programming is "Pro Ado.Net 2.0" there is also an electronic version of this book available for purchase and download on Amazon. I would highly suggest this as a starting point.


You can create a view of your table and then use Find & Filter methods available. This has performance benefits over using datatable select methods which then lose table indexing.

The record is either added/inserted to the dataset/datatable or it is not. AcceptChanges will only change the rowstate (if it already exists in the dataset) of the record from New to Unchanged and will then prevent the record from then being saved to the database since the datatable sees it as unchanged.

Iammirko can you show an example of how your checking if this record is inserted? Also I dont see in this example where your creating an instance of this dataset and pointing the table adapter to it.

Im trying to understand your project and a bit confused. Why would you want to extract data from the XML file and store in multiple flat text files? It would seem to me (without know more about your project) that it would be easier to keep everything in the xml file and its very easy to read/write to & from that file.

It is much more efficient (specially using access) to store just the file name & path of your file in the database and retrieve that info to use in loading your file. Images take up larges amounts of space and everytime you edit a record that contains a picture (even if your not changing the picture itself) the database makes a new copy of that record which keep accumalating the size of your database.

You dont need to automate Excel at all to output your dataset/datatable to an Excel file. You can use OLEDB to create your file.

Also Im not sure what the insert line is doing (the first line) you have already added the rows to the table in the first example unless you removed that coding too...

Altogether I would say the all that is needed is your orginal example which adds the new rows to your dataset & datatable and then the call to the DataAdapter.Update method right after that which saves all the changes in the datatable/dataset to the database.