TomW 73 Posting Whiz

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

Add to your menu item events:

mnuUnitedStates_Click
mnuMexico.Checked = Not mnuUnitedStates.Checked
End Sub

mnuMexico_Click
mnuUnitedStates.Checked = Not mnuMexico.Checked
End Sub

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz
intTotalRecordsUpdated = command.ExecuteNonQuery()
TomW 73 Posting Whiz

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"))
        Console.ReadLine()

    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
            Else
                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
TomW 73 Posting Whiz

Here let me google that for you

You could even possibly take that one step further and adding the type of database you want to back up...

TomW 73 Posting Whiz

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
TomW 73 Posting Whiz

>will you provide some real good example on backgroundworker control in vb.net for doing some process in background.

Not the real question. Let me google that for you.

Excellent answer. And surprising how much it applies to such a majority of the entire threads posted.

TomW 73 Posting Whiz

Theres a few books on the subject over on amazon

TomW 73 Posting Whiz

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
    frm.Show()

End Sub
TomW 73 Posting Whiz

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

TomW 73 Posting Whiz

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

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

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

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

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 …

TomW 73 Posting Whiz

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.)

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

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)

TomW 73 Posting Whiz

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

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz
TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

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.

TomW 73 Posting Whiz

Perfect sense, the DataAdapter.Update is what sends the new records to the database. The AcceptChanges isnt needed (its redundent), the call to the Update method automatically changes the records row state to Unchanged as it completes the update for each row. Calling the AcceptChanges after that changes any un-updated records to unchanged but since that was already done...

TomW 73 Posting Whiz

Take a look at AcceptChanges in the help file, it does not insert data to the database. I cant say much besides that since I dont know what else your code is doing.

TomW 73 Posting Whiz

cboMonthC.Items(""))
The parameter should be an interger value not a string

TomW 73 Posting Whiz

The footer section is not like the details section and does not list multiple records. Its more for summaries (single rows) type of info. Im not sure of the type of info your looking to display but try taking a look at grouping the sections, this may answer your question.

TomW 73 Posting Whiz

Ok I'm lost I guess because this is marked as solved. AcceptChanges does not save the data to the database; it instead changes the row state properties of the dataset/datatable making the new records to UnChanged so that they cant be saved to a database when calling update.

TomW 73 Posting Whiz

Here are some tutorials for working with VB.Net & Sql Server:
Data Walkthroughs

Here is a link dedicated soley to connection strings:
Connection Strings

TomW 73 Posting Whiz

Agree with Adapost, not many will help those that at least are not attempting to do the work for themselves. A quick suggestion that may help though, using the proper controls will help make validation easier. Such as using the NumericUpDown control instead of a textbox to allow only numeric entries.

kvprajapati commented: Well said. +6
TomW 73 Posting Whiz

There are several ways you can accomplish this. You can either define there security through coding as mentioned above and then handle it in the project depending on the users level or you can define it right in Sql Server itself by assigning the proper permissions per table for each of the users.

TomW 73 Posting Whiz

If you want an inputbox where the user enters the input into the messagebox, then you do have to assign the return value to a string variable. But as Sknake say above, its not needed if it is only displaying a message.

TomW 73 Posting Whiz

Lots of different ways you can do the import but automatting Excel is probably the last one I would pick. First if you are importing directly from an Excel file, there is no reason to automate Excel at all. Using OLEDB you can read the values straight from the file into a dataset/datatable. This has an added advantage of not needing the user to also have the same version of Excel installed on the computer. Second there is no need to convert a CSV file before doing an import, there are many methods available for reading/importing delimited files. Not that it matters but you mention your using ODBC to read the Excel file, I dont see ODBC being used at all in your example.

I would suggest starting out by taking a look at the "TextFieldParser" in the help file. It has full examples for reading delimited files without the need to convert them to a different format.

TomW 73 Posting Whiz

Its pretty easy, your basically just making a different connection string that attaches to the file rather then to a database. Plenty of examples online showing how to do it. If your unable to figure it out, let me know and I can provide more details

TomW 73 Posting Whiz

Nothing really needed, just add a Module file and start creating your public or private subs & functions. If created as public they can be seen and accessed from anywhere else in your project. The only thing really different in a module file is the declaration of variables. If you want to access global variables in a module file from outside it, you must use the Public keyword instead of Dim.

TomW 73 Posting Whiz

Public Subs/Functions are best off put into a module file so that all forms within a project can access these methods.

TomW 73 Posting Whiz

Is this being run on a different computer then what it was created? Reference problems like this are usually a case of having a different version of Excel (or no version) then which it was created on.

With that said, it seems you are simply listing file directories into excel. You could instead have this info fill a dataset/datatable and output it as an Excel file using OleDb without the need of automating Excel or even requiring the user computers to have Excel.

TomW 73 Posting Whiz
TomW 73 Posting Whiz

All programming languages are dependent on some type of base class files that it calls for functionality. Dot net attempts to include all in the dot net framework instead of a ton of seperate files (dll hell) . Even languages such as C++ will use system dll files.

TomW 73 Posting Whiz

Seem to be that it is expecting you to pass an integer value in the c.GetDisplayText function but instead you are passing a tab string. Of course im only taking a guess here since I dont know what your function parameters are...

TomW 73 Posting Whiz

None of the parameters even have datatypes defined.... An overflow error is usually caused by trying to force a bad value that doesnt fit into a specific datatype.

TomW 73 Posting Whiz

I guess that mostly depends on what info you are displaying. If you want to display multiple records at a time I would use a DGV. If it is only one record at a time then controls such as Labels or Textboxes can be used.

TomW 73 Posting Whiz

The problem is in your connection statement. Your specifying the database twice, each a different way and your not specifying the security.