Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Whoever solves the mystery wins a prize

  • 15-05-2007 11:20am
    #1
    Closed Accounts Posts: 110 ✭✭


    Heres my code written in visaual basic 2005 express edition.
    If i take out the two lines of code in red it works OK, but what can be the problem with those lines?
    In the database the Field "Day" is supposed to take in Integers but for some reason it will not update although it will update the cusnum which is also a Integer!!!!





    Public Class VehRegEnter



    Dim MAXCARS As Integer = 50

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub

    Private Sub Back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Back.Click
    BookOrPay.Show()
    Me.Close()
    End Sub

    Private Sub Forward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Forward.Click
    UP()
    End Sub

    Private Sub UP()


    Dim con As New OleDb.OleDbConnection
    Dim ds As New DataSet
    Dim da As OleDb.OleDbDataAdapter
    Dim SelectCustomer As String = "SELECT * FROM Details"
    con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = E:\DB.mdb"
    con.Open()
    da = New OleDb.OleDbDataAdapter(SelectCustomer, con)
    da.Fill(ds, "TABLE")
    'The next linecalls Rand to get a Random number to assign to Customer number between 1000 and 9999
    Dim CustomerNumber As Integer = Rand(1000, 9999)
    Dim count As Integer = 2

    'While LOOP to make sure that customer number is not already in use
    'and to make sure that car is not already in carpark
    While (count < MAXCARS)
    ' make sure that car is not already in car park
    If (TextBox1.Text = ds.Tables("TABLE").Rows(count).Item(1)) Then
    MessageBox.Show("This Car Is Already Registered In Car Park: Please Wait For Assistance")
    Me.Close()
    count = 500
    Close()
    End If
    count = count + 1
    End While
    If (count <> 500) Then
    count = 2
    End If
    'Make Sure customer number is not in use
    While (count < MAXCARS)

    If (CustomerNumber = ds.Tables("TABLE").Rows(count).Item(0)) Then
    CustomerNumber = Rand(1000, 9999)
    count = -1
    End If
    count = count + 1
    End While


    If (count <> 500) Then
    count = 2
    End If

    'Add Car To DataBase with start time


    While (count < MAXCARS)
    If (ds.Tables("TABLE").Rows(count).Item("VACANT") = "Y") Then
    Dim h As Integer = Now.Hour
    MessageBox.Show(h)
    Dim cb As New OleDb.OleDbCommandBuilder(da)

    MessageBox.Show(ds.Tables("TABLE").Rows(count).Item("Day"))

    ds.Tables("TABLE").Rows(count).Item("Day") = 5
    ds.Tables("TABLE").Rows(count).Item("Vacant") = "N"
    ds.Tables("TABLE").Rows(count).Item("Discount") = "N"
    ds.Tables("TABLE").Rows(count).Item("RegNum") = TextBox1.Text
    ds.Tables("TABLE").Rows(count).Item("CusNum") = CustomerNumber



    ds.Tables("TABLE").Rows(MAXCARS).Item("Day") = ds.Tables("TABLE").Rows(count).Item("Day")
    ds.Tables("TABLE").Rows(MAXCARS).Item("Vacant") = ds.Tables("TABLE").Rows(count).Item("Vacant")
    ds.Tables("TABLE").Rows(MAXCARS).Item("Discount") = ds.Tables("TABLE").Rows(count).Item("Discount")
    ds.Tables("TABLE").Rows(MAXCARS).Item("RegNum") = ds.Tables("TABLE").Rows(count).Item("RegNum")
    'NEXT LINE MAKES SURE THAT THE PRIMARY KEY VALUE IS NOT INTERFERED WITH
    ds.Tables("TABLE").Rows(MAXCARS).Item("CusNum") = ds.Tables("TABLE").Rows(count).Item("CusNum") + 9999
    Try
    MessageBox.Show(ds.Tables("TABLE").Rows(count).Item("CusNum"))
    da.Update(ds, "TABLE")
    'con.Close()
    Catch
    UP()
    End Try

    MessageBox.Show("UPDATED")
    'Set count to this number to avoid next if statement
    count = MAXCARS + 25
    End If
    count = count + 1
    End While

    If (count = MAXCARS) Then
    MessageBox.Show("NO FREE SPACES")
    Me.Close()
    End If


    'con.Close()

    CustNoPrintPage.Show()
    Me.Close()
    End Sub


    'This function returns a random number
    Public Function Rand(ByVal Low As Long, _
    ByVal High As Long) As Long
    Rand = Int((High - Low + 1) * Rnd()) + Low
    End Function

    Private Sub Help_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Help.Show()
    Me.Close()
    End Sub

    Private Sub VehRegEnter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    End Sub


    End Class


Comments

  • Registered Users, Registered Users 2 Posts: 995 ✭✭✭cousin_borat


    You probably have Day field defined as a Character column in your table rather than as a number which is what you're trying to insert


  • Registered Users, Registered Users 2 Posts: 273 ✭✭stipey


    Any chance you could give us the text of the error message you are receiving when the offending lines are left in?


Advertisement