TomW 73 Posting Whiz

I dont know what your database/table structures look like, what columns they contain or even what calculations you may need but calculating returned results is pretty straight forward.

Select (Column1 + Colum2) As TotalBlah From myTable
Select (colQuanity * colPrice) As ItemTotal From myTable
etc

TomW 73 Posting Whiz

Here is a C# example that shows how to add a picture to a dataset and display in a Crystal Report.

TomW 73 Posting Whiz

If all is working please mark the thread as solved.

TomW 73 Posting Whiz

Taking a closer look at your query I would also add you dont need multiple sub-queries all on the same table.

TomW 73 Posting Whiz

I would suggest setting the column to not allow nulls and its default value to zero. Since this is an existing table you might first need to run an update statement to replace nulls with zero before making the table changes.

TomW 73 Posting Whiz

I think your making it more complicated on the front end then needs to be. As long as you can properly store each of this bits of info to the database, you should then be able to write a query to retrieve the info and calculate it at that time.

For instance it seems that your trying to record totals which is something that can constantly change. Instead record/save the quanties and then calculate your totals in your sql query.

TomW 73 Posting Whiz

You can bind a DataSet/DataTable to a Listbox and have it automatically show one field as the DisplayMember and hide the Id within its ValueMember item property.

Since you have 3 columns of information, I would suggest not even using a ListBox but instead use a DataGridView or ListView control that will allow showing all 3 columns of data. Especially considering that you said that this can be large amounts of data, I would reconsider not using a listbox.

However if you are still determined to use it, my personally suggestion would be to concatenate two of the fields you want to display into a single column and attach the additonal column to the value member.

Such as in your query

Select  IndexId, (Name + ' - ' + Value) As DisplayItm From MyTable

This will return two columns of info, then you just need to bind to your listbox

ListBox1.DataSource = myDataSet.myTable
ListBox1.DisplayMember = "DisplayItm"
ListBox1.ValueMember = "IndexId"
TomW 73 Posting Whiz

Again I would ask are you sure the record is not being updated in the actual database and your just not seeing it on the front end? I dont see where its doing a refill of the new data except in the page load. Also have you stepped thru the code to see the exact values that are in the parameter variables at the time it is executed; it might be something unexpected?

I would change your fill in the page load, to fill a form/global scope level dataset rather then using a reader to store the values in your controls. Then in your update button, I would make the update to the existing record in your dataset. Then call the update method of the dataadapter to update the database on the entire dataset.

TomW 73 Posting Whiz

I would suggest something like:

Private Sub FillDataset()

        Using con As New SqlConnection(strMyConnectionString)
            Dim cmdSelect As New SqlCommand
            Dim da As New SqlDataAdapter

            With cmdSelect
                .Connection = con
                .CommandType = CommandType.Text
                .CommandText = "Select * From VwBarcodeTotals Where AccountNo = @AccountNo"
                .Parameters.AddWithValue("@AccountNo", ComboBox1.SelectedValue.ToString)
            End With

            da.SelectCommand = cmdSelect
            da.Fill(ds, "BarcodeTotals")

            da.Dispose()
            cmdSelect.Dispose()
        End Using 'con

End Sub
TomW 73 Posting Whiz

A primary key sounds perfect for filtering your database. Let me ask to be sure, is AccountNo a numeric datatype or text/string datatype?

TomW 73 Posting Whiz

This code does not produce errors but it does not execute any update.

Chris are you checking the actual database or just your in-memory dataset. Since the coding is directly updating the database with values from textboxes rather then first adding a new datarow to the dataset/datatable, you will not see the changes in the dataset/datatable until the next time you perform a fill operation.

TomW 73 Posting Whiz

Mine was funnier... :)~

sknake commented: i'll give you that +5
TomW 73 Posting Whiz

Glad to help.

Well if you use a loop instead of a timer, you would have to keep track of the start time and with each itteration check the current time to see how much time has passed. The loop is easy, working with datetime functions and the timespan object get a bit more involved though.

If you type in "StopWatch" into the help file, it has a nice downloadable example of a stopwatch type of program. It shows how you can compare and format elapsed time for display.

TomW 73 Posting Whiz
Beep()
TomW 73 Posting Whiz

Using the IndexOf method of an array that .Net provides will save you from having to write tons of If comparisons and is much faster in its execution.

Sub Main()
        Dim arrVowels() As String = {"a", "e", "i", "o", "u"}
        Dim strSearchText As String = "Programming"
        Dim intVowelCounter As Integer = 0

        For Each c As Char In strSearchText
            If Array.IndexOf(arrVowels, c.ToString.ToLower) >= 0 Then intVowelCounter += 1
        Next
        Console.WriteLine("Number of Vowels Found: {0}", intVowelCounter)

        If intVowelCounter = strSearchText.Length Then
            Console.WriteLine("All letters in the search text are vowels")
        End If
        Console.ReadLine()
End Sub
TomW 73 Posting Whiz

The equals sign is not the problem, its the method of retrieving your text from the combobox that changed. A combox item can have two values, the DisplayMember which is the text that is displayed as each item in the cbo and a hidden value can be assigned to each item in the ValueMember property. cbo.SelectedValue will return the value member but you also need to convert its value into its proper datatype. Such as

cbo.SelectedValue.ToString
or
CInt(cbo.SelectedValue)

Two things I would suggest, for getting the display text as it appears you are trying to do, use the following
cboBarcodeInCust.GetItemText(cboBarcodeInCust.SelectedItem)

The SelectedIndexChanged event will fire multiple times when your first loading your combobox. I would suggest either adding coding to exit the event during your initial load/fill or move your coding to the SelectionChangeCommitted event.

scooby36 commented: Very Good advise Thanks +1
TomW 73 Posting Whiz

You sound like your trying to understand all that is going on with the code; so that is good. I didnt add comments to this to allow ya to think about it but if you need an explaination just ask.

Timer interval is set to 1,000

Personally I would do this with a loop, the StopWatch class and the TimeSpan object but I dont wanna get to far ahead of where your at in school.

Public Class Form1

    Dim m_intCounter As Integer = 0

    Private Sub btnStart_Click(...) Handles btnStart.Click

        If btnStart.Text = "Start" Then
            btnStart.Text = "Stop"
            m_intCounter = 0
            Timer1.Enabled = True
        Else
            btnStart.Text = "Start"
            lblTrafficLight.Text = ""
            lblTrafficLight.BackColor = Me.BackColor
            Timer1.Enabled = False
        End If

    End Sub

    Private Sub Timer1_Tick(...) Handles Timer1.Tick

        If m_intCounter >= 40 Then
            m_intCounter = 1
        Else
            m_intCounter += 1
        End If

        Select Case m_intCounter
            Case 1 To 20
                lblTrafficLight.Text = "Red"
                lblTrafficLight.BackColor = Color.Red
            Case 21 To 36
                lblTrafficLight.Text = "Green"
                lblTrafficLight.BackColor = Color.Green
            Case 37 To 40
                lblTrafficLight.Text = "Yellow"
                lblTrafficLight.BackColor = Color.Yellow
            Case Else
                'Do nothing
        End Select

    End Sub

End Class
TomW 73 Posting Whiz

Again I wouldnt use 3 different timers but if it is required by your class specifications, I added an example with using 3 different timers.

TomW 73 Posting Whiz
Private Sub btnStart_Click(...) Handles btnStart.Click

        If btnStart.Text = "Start" Then
            btnStart.Text = "Stop"
            lblTrafficLight.Text = "Red"
            timRed.Enabled = True
        Else
            btnStart.Text = "Start"

            Select Case True
                Case timRed.Enabled
                    timRed.Enabled = False
                Case timGreen.Enabled
                    timGreen.Enabled = False
                Case timYellow.Enabled
                    timYellow.Enabled = False
            End Select
        End If

    End Sub

    Private Sub timRed_Tick(...) Handles timRed.Tick
        lblTrafficLight.Text = "Green"
        timGreen.Enabled = True
        timRed.Enabled = False
    End Sub

    Private Sub timGreen_Tick(...) Handles timGreen.Tick
        lblTrafficLight.Text = "Yellow"
        timYellow.Enabled = True
        timGreen.Enabled = False
    End Sub

    Private Sub timYellow_Tick(...) Handles timYellow.Tick
        lblTrafficLight.Text = "Red"
        timRed.Enabled = True
        timYellow.Enabled = False
    End Sub
PcPro12 commented: helped me solve my problem completely, THANKS!!! :D +4
TomW 73 Posting Whiz

I think your confusing yourself with so many different timers. I would suggest only using one timer (interval to one second) and through coding keep track of the elapsed time and which light should be displayed. Also take a look at "StopWatch" in the help file it shows how to get, format & display elapsed time.

TomW 73 Posting Whiz

Again because it is managing to overlook the error(s) and do the calculation anyway does not change the fact that you still have unseen errors.

If you type the below at the very top of your code form you will see the errors.

Option Strict On
Option Explicit On

'This is still a text being added to a number and then 
'forcing the resulting number to be displayed back as text

TextBox1.Text = +(TextBox1.Text + 1800)

Much better coding standards would be to convert the values to there proper datatypes.

TomW 73 Posting Whiz

everytime im trying to do it it add it like this
36001800

never add just put :S

This is an example of concatenating two strings rather then calculating two numeric values

TomW 73 Posting Whiz

The problem is that your trying to perform calculations on text values. You need to convert the text values to a numeric datatype. Even your last post would show as an error if you turned Option Strict & Option Explicit On.

'Convert the existing textbox value to an Int before calculating
'Convert the final answer back to a string for storage in a textbox

TextBox1.Text = CStr(CInt(TextBox1.Text) + 1800)
TomW 73 Posting Whiz

You should start your own thread for new questions. But to quickly answer your question, you want to work with the underlying datasource that is connected to the datagridview. For instance if it is a datatable that is connected, you want to set the table with the boolean column to true

TomW 73 Posting Whiz

This is easy enough to accomplish but I would suggest against it since it would mean having to include a timer event that is constantly running throughout your program to update the time. As for adding your form name, add a status strip and on your status strip add a StatusLabel, in your coding assign the form name to the status label as so:

'Recommend re-naming to something more meaningfull
ToolStripStatusLabel1.Text = Me.Name
TomW 73 Posting Whiz

Any part of this program your actually writing yourself? :)

How to: Create Application Settings Using the Designer

TomW 73 Posting Whiz
TomW 73 Posting Whiz

You are correct there .Net does not offer control arrays. You can use control collections in coding to itterate through the controls on a form or in a container.

For Each ctl As Control In Me.Controls
        If TypeOf (ctl) Is TextBox Then
            MessageBox.Show(ctl.Name)
        End If
Next
TomW 73 Posting Whiz

Added comments

Sub Main()

        Dim arrGrades(4) As Integer
        Dim intTotal As Integer = 0

        'Get input
        For intIndex = 0 To 4
            Console.Write("Enter the " & intIndex + 1 & " received grade: ")

            'Input values are text so I am converting the text of
            'the grade entered into a numeric datatype (integer) for 
            'future calculation and storing the value into the array.
            arrGrades(intIndex) = CInt(Console.ReadLine())
        Next

        Console.WriteLine()
        Console.WriteLine("######################################")
        Console.WriteLine()

        'Display Grades
        For intIndex = 0 To 4

            'Use of the placeholders simply avoids string concatenation
            'The first placeholder {0} is the intIndex +1
            'The second is the index of where the grade is being
            'stored in the array. The .ToString converts it from the
            'the numeric datatype (integer) back into a string for display.
            Console.WriteLine("Grade {0} : {1}", (intIndex + 1), arrGrades(intIndex).ToString)

            ' The below is just adding all the grades up into a total
            intTotal += arrGrades(intIndex)
        Next

        Console.WriteLine()
        Console.WriteLine("######################################")
        Console.WriteLine()

        ' For the average I'm just dividing the total by 5
        ' The format number is a way to make sure that 
        ' that you dont get an answer that has more then
        ' 2 places passed the decimal point displayed.
        'The formatnumber method at the same time is 
        'converting the numeric value into a string.
        Console.WriteLine("Average Grade : {0}", FormatNumber(intTotal / 5, 2))

        Console.WriteLine("Press Enter key to exit")
        Console.ReadLine()
    End Sub
TomW 73 Posting Whiz

Im glad it worked for ya; dont forget to mark the thread as solved. I attempted to keep the coding similar to your original example as to not jump ahead of your level but if you need any explaination of what I did, just ask. I think the only differences were converting datatypes properly and the formatting for display.

TomW 73 Posting Whiz

You can embed the wav files into your project by adding them to the project Resources.

TomW 73 Posting Whiz
Sub Main()

        Dim arrGrades(4) As Integer
        Dim intTotal As Integer = 0

        'Get input
        For intIndex = 0 To 4
            Console.Write("Enter the " & intIndex + 1 & " received grade: ")
            arrGrades(intIndex) = CInt(Console.ReadLine())
        Next

        Console.WriteLine()
        Console.WriteLine("######################################")
        Console.WriteLine()

        'Display Grades
        For intIndex = 0 To 4
            Console.WriteLine("Grade {0} : {1}", (intIndex + 1), arrGrades(intIndex).ToString)
            intTotal += arrGrades(intIndex)
        Next

        Console.WriteLine()
        Console.WriteLine("######################################")
        Console.WriteLine()

        Console.WriteLine("Average Grade : {0}", FormatNumber(intTotal / 5, 2))
        Console.WriteLine("Press Enter key to exit")

        Console.ReadLine()

    End Sub
TomW 73 Posting Whiz

Or in your project you can goto the properties window and click the checkbox that says "Make Single Instance application"

TomW 73 Posting Whiz

Seems like a silly question but did you actually create any tables within your dataset?

TomW 73 Posting Whiz

ahhh keyword, good catch...

As far as the missing data, make sure your not using two different versions of access, one that is your original and another that is just a copy of the original in your project.

TomW 73 Posting Whiz

Access gives weird error messages if you type the wrong column name. Move your query over to the MS Access designer and see if you can run it with the substituted parameter values as a test. I'm almost certain you get a syntax error instead of a "column does not exist" error in updates with access.

I'm kinda wondering about the error msg myself. Technically it shouldnt even know its an Update Statement, its not assigned to an update command of a data adapter.

TomW 73 Posting Whiz

Try taking out the conn.createcommand

Dim command As OleDbCommand = new oledbcommand
command.Connection = conn
TomW 73 Posting Whiz

Are you familar with Typed Datasets within your project? I add a dataset file to my project and create some tables within it to match the db tables & fields I want to work with in the database. Thats it.... (besides of course my coding to fill & work with the dataset but thats done elsewhere in my projects)

When you create a new report and the wizard dialog asks for a datasource, you will see that one of the options is for Ado.Net datasets, you can navigate directly to the dataset file within your project or point it to any dataset file (.xsd) file from any other project on your PC.

Your report will then have all the tables & fields available to you that are included in that dataset to work with although the dataset file itself is not directly connected to any info.

TomW 73 Posting Whiz

Relooking at my example, my syntax was incorrect and I hope you caught this mistake. I didnt use a comma between each of the columns & values and instead used the key word "And". Thats what I get for attempting to code in this webpage textbox... lol

strSQL = "Update [Employee] Set First_Name = @FName, Last_Name = @LName  Where Employee_ID =  @Id"

Parameters are pretty easy, I dont know why they dont push it more then the concatenated strings. Below is a quick example and here is a link for some more detailed info Configuring Parameters and Parameter Data Types (ADO.NET)

strSQL = "Update [Employee] Set First_Name = @FName And Last_Name = @LName  Where Employee_ID =  @Id"

command.Transaction = myTransaction       
command.CommandType = CommandType.Text            
command.CommandText = strSQL

Command.Parameters.AddWithValue("@FName", txtFName.Text)
Command.Parameters.AddWithValue("@LName", txtLName.Text)
Command.Parameters.AddWithValue("@Id", cint(txtStaffId.Text))

command.ExecuteNonQuery()
TomW 73 Posting Whiz
samir_ibrahim commented: Very usefull Link +2
TomW 73 Posting Whiz

By calling the AcceptChanges method on a Dataset and/or DataTable you are changing the rowstate of all the records to "Unchanged". Later when you call DataAdapter.Update method, it will do nothing because none of the records are marked as modified.

Here's a quote I made in another post a few days ago

' Explicitly calling a Dataset/DataTable's AcceptChanges method
' seems to be a very common mistake by many programmers.
' In truth this is rarely needed. Your DataAdapter will automatically
' adjust the row state changes after any action command has
' been executed.

TomW 73 Posting Whiz
TomW 73 Posting Whiz

I'm not sure what is causing your datasource problem with crystal reports but just to offer an alternative suggestion...

When I create a crystal report I dont even assign it to a datasource or database; instead I connect it to a dataset. Then in my program, I fill my dataset to display to users and when there ready for the report, I just pass the filled dataset as the datasource. This has a few advantages such as the report not having to connect to the db and requery info that you may already be working with in a program.

TomW 73 Posting Whiz

Take a look at "StopWatch" in the help file. It has a nice example showing how to work with the StopWatch Class, TimeSpan object and how to format the hours, minutes & seconds for display.

The above timer example is the opposite of what you want (counting elapsed time as it proceeds) instead of couting down but all the formatting is the same.

To count down, you would use the same principals as above except that you would need to store the time when you start your function, and then when you check (such as in a timer tick event) subtract the current time from the start time to find out the difference.

TomW 73 Posting Whiz

Parameters are pretty easy, I dont know why they dont push it more then the concatenated strings. Below is a quick example and here is a link for some more detailed info Configuring Parameters and Parameter Data Types (ADO.NET)

strSQL = "Update [Employee] Set First_Name = @FName And Last_Name = @LName  Where Employee_ID =  @Id"

command.Transaction = myTransaction       
command.CommandType = CommandType.Text            
command.CommandText = strSQL

Command.Parameters.AddWithValue("@FName", txtFName.Text)
Command.Parameters.AddWithValue("@LName", txtLName.Text)
Command.Parameters.AddWithValue("@Id", cint(txtStaffId.Text))

command.ExecuteNonQuery()
Kristofferson commented: Helpful and non condescending, thats always a plus. +1
sknake commented: Parameterized SQL is always the best way +5
TomW 73 Posting Whiz

Comma's look fine although the double set of quotes at the end of the where clause is not needed (it shouldnt hurt anything). Also in your catch block you should include a myTransaction.Rollback

TomW 73 Posting Whiz

Each of the string/text field values should be surrounded by single quotes in your update statement. However I would suggest changing this concatenated string to use parameters instead;. it will take care of not having to surrond the values in quotes and the database wont have to parse your statement multiple times times to format it for missing parameters.

TomW 73 Posting Whiz

Use a timer....

Nattynooster commented: Sarcastic. Never used a timer before, quite new to VB +0
sknake commented: You don't deserve -rep for a good solution +5
TomW 73 Posting Whiz

Are you refilling your datatable after performing your insert statement?

TomW 73 Posting Whiz

Sorry, the word "In" was supposed to be "Is" in my last post.

You seem to be attempting to manually generate your "Id" field value getting the last record value and increasing it by one.

In the database you can set a column as an identity seed where it will automatically increment the field number whenever you add a new record. I was wondering if your database column is set up to do this?