none
Visual Basic.net 2013 And Ms Access 2013 RRS feed

  • Question

  • I'm having trouble in calculating book fines. Here's my code:

    UPDATE

    Dim conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\huzai_000\Desktop\HND YEAR 1\HND Year1 assignments\Projects\Library project\Library Management System\Library Management System\Library.accdb")
    
            conn.Open()
    
            Dim cmd As OleDbCommand
    
            cmd = New OleDbCommand("UPDATE Book_Transaction SET Bk_TID=" & Bk_TIDTextBox.Text & " ,  Library ID='" & Library_IDTextBox.Text & "', Book ID='" & Book_IDTextBox.Text & "' , IssueDate='" & IssueDateDateTimePicker.Text & "' , [Date Due Back]='" & Date_Due_BackDateTimePicker.Text & "' , [ReturnDate]='" & ReturnDateDateTimePicker.Text & "' where Bk_TID=" & Bk_TIDTextBox.Text & ")", conn)
    
            cmd.Connection = conn
    
            If (conn.State = ConnectionState.Open) Then
    
                Try
    
                    'cmd.Parameters.Add("@MemberID", OleDbType.VarChar).Value = Member_IDTextBox.Text
    
                    cmd.Parameters.Add("@Bk_TID", OleDbType.Integer).Value = System.Convert.ToInt32(Bk_TIDTextBox.Text)
    
                    cmd.Parameters.Add("@LibraryID", OleDbType.VarChar).Value = Library_IDTextBox.Text
    
                    cmd.Parameters.Add("@BookID", OleDbType.VarChar).Value = Book_IDTextBox.Text
    
                    cmd.Parameters.Add("@IssueDate", OleDbType.Date).Value = IssueDateDateTimePicker.Text
    
                    cmd.Parameters.Add("@DateDueBack", OleDbType.Date).Value = Date_Due_BackDateTimePicker.Text
    
                    cmd.Parameters.Add("@ReturnDate", OleDbType.Date).Value = ReturnDateDateTimePicker.Text
    
                    cmd.ExecuteNonQuery()
    
                    MessageBox.Show("Data Updated Successfuly to Book Transaction", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
    
                    conn.Close()
    
                Catch ex As Exception
    
                    MessageBox.Show(ex.Source)
    
                    MessageBox.Show(ex.Data.ToString())
    
                    MessageBox.Show(ex.Message)
    
                    conn.Close()
    
                End Try
    
            Else
    
                MessageBox.Show("Connection Failed")
    
            End If
    
            Dim DateReturned As Date = Convert.ToDateTime(ReturnDateDateTimePicker.Text)
    
            Dim DateDue As Date = Convert.ToDateTime(Date_Due_BackDateTimePicker.Text)
    
            If DateReturned > DateDue Then
    
                Dim DaysLate As TimeSpan = DateReturned.Subtract(DateDue)
    
                Dim Fine As Double = DaysLate.Days * 0.5
    
                MessageBox.Show("Fine = {Fine.ToString:c}")
    
            Else
    
                MessageBox.Show("Fine = 05.00 AED", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    
            End If

    Wednesday, January 17, 2018 6:45 AM

Answers

  • Hi Huzaifa,

    I don't see any error in your code, can you tell me what issue you encounter, where you encounter this issue?

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 18, 2018 2:42 PM
    Moderator

All replies

  • What error you are getting? It is always helpful to diagnose if you can provide the error. 

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Wednesday, January 17, 2018 7:22 AM
  • This is the forum you should be posting to, since this is the C# forum and not the VB forum.

    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral

    Wednesday, January 17, 2018 7:34 AM
  • Hello,

    Please explain the exact issue you are having in regards to calculating as we can't just copy your code and run it.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Wednesday, January 17, 2018 10:19 AM
    Moderator
  • Hi Huzaifa,

    I don't see any error in your code, can you tell me what issue you encounter, where you encounter this issue?

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 18, 2018 2:42 PM
    Moderator
  • Huazifa,

    This code won't run, you insert values in your SQL code while you also try to add parameters. 

    Here on this page a simple sample how to use parameters with OleDB (it are no named parameters in OleDb)

    http://www.vb-tips.com/OleDBParameters.aspx


    Success Cor

    Thursday, January 18, 2018 4:52 PM