-
Jan 15th, 2021, 06:33 PM
#1
Thread Starter
Junior Member
I'm typing in a textbox linked to a database and it stops everything from working.
So I am using a Data Set to insert items into my Microsoft Access Database, but whenever I type in the "CustomerID" Textbox, I am then prevented from doing anything, buttons won't work, Even the windows close form button gets disabled.
Code:
Option Explicit On
Option Strict Off
Public Class ManagePodBookings
Private Sub ManagePodBookings_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Loads the Pod Booking Database
RefreshData()
Me.PodBookingsTableAdapter.Fill(Me.PodBookingsDataSet.PodBookings)
End Sub
Private Sub btnBack_Click(sender As Object, e As EventArgs) Handles btnBack.Click
'Shows the staff form
Staff.Show()
Me.Hide()
End Sub
Private Sub btnMainMenu_Click(sender As Object, e As EventArgs) Handles btnMainMenu.Click
'shows the main menu
MainMenu.Show()
Me.Hide()
End Sub
Private Sub PodComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles PodComboBox.SelectedIndexChanged
'Making it so users cannot edit ComboBox values
PodComboBox.DropDownStyle = ComboBoxStyle.DropDownList
End Sub
'Making it so users cannot edit ComboBox values
Private Sub RefreshData()
'Refreshing the table data
Try
Me.PodBookingsBindingSource.Filter = Nothing
Me.PodBookingsTableAdapter.Fill(Me.PodBookingsDataSet.PodBookings)
Catch ex As Exception
MsgBox("There was an error refreshing the data.")
End Try
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
'Adds a New Record within the Data Table.
Try
With btnAdd
If .Text = "Add New Record" Then
PodBookingsBindingSource.AddNew()
PeopleNumericUpDown.Value = 0
ArrivalDateDateTimePicker.Value = Now.Date
DepartureDateDateTimePicker.Value = Now.Date
.Text = "Cancel New Record"
Else
RefreshData()
.Text = "Add New Record"
End If
End With
Catch ex As Exception
MsgBox("There was an error adding a new record." & ex.Message.ToString(),
MsgBoxStyle.OkOnly Or MsgBoxStyle.Information)
End Try
End Sub
Private Sub Save_Click(sender As Object, e As EventArgs) Handles btnSave.Click
'Handles the save button
Try
Dim result As DialogResult
result = MessageBox.Show("Do you want to save the selected record?",
"Glorious Getaways", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If (result = DialogResult.Yes) Then
Validate()
PodBookingsBindingSource.EndEdit()
TableAdapterManager.UpdateAll(Me.PodBookingsDataSet)
MessageBox.Show("The record has been saved successfully.",
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Information)
RefreshData()
btnAdd.Text = "Add New Record"
Else
Return
End If
Catch ex As Exception
MessageBox.Show("There was an error Saving the Data." & ex.Message.ToString(),
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub Delete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
'Deletes a record from the Data Table
Try
If MessageBox.Show("Do you want to permanently delete the selected record?",
"Glorious Getaways", MessageBoxButtons.YesNo,
MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) =
Windows.Forms.DialogResult.Yes Then
PodBookingsBindingSource.RemoveCurrent()
PodBookingsBindingSource.EndEdit()
PodBookingsTableAdapter.Update(PodBookingsDataSet.PodBookings)
RefreshData()
MessageBox.Show("The record has been deleted sucessfully.",
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Return ' Exit Sub
End If
Catch ex As Exception
MessageBox.Show("There was an error deleting the Data." & ex.Message.ToString(),
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub SearchWarning()
'Disabling search whilst adding new record.
MsgBox("You are unable to Search whilst adding a new Record.",
MsgBoxStyle.OkOnly Or MsgBoxStyle.Exclamation,
"Glorious Getaways")
End Sub
Private Sub SearchBox_Click(sender As Object, e As EventArgs) Handles Search.Click, btnSearch.Click
'Disabling search whilst adding new record.
If btnAdd.Text = "Cancel New Record" Then
SearchWarning()
Exit Sub
End If
End Sub
Private Sub SearchButton_Click(search As Object, e As EventArgs) Handles btnSearch.Click
If PodBookingsBindingSource.Count < 1 Then
MsgBox("The search item was not found.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
"Glorious Getaways")
RefreshData()
End If
Try
Catch ex As Exception
MessageBox.Show("There was an error when Searching." & ex.Message.ToString(),
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs)
Try
Me.PodBookingsTableAdapter.FillBy(Me.PodBookingsDataSet.PodBookings)
Catch ex As System.Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
End Try
End Sub
End Class
This is the code I have used, I'm currently working on a search button to search the database for specific strings inputted into a search text box.
Last edited by THopwood; Jan 16th, 2021 at 02:19 PM.
-
Jan 15th, 2021, 06:58 PM
#2
Re: I'm typing in a textbox linked to a database and it stops everything from working
Is the unasked question how to get your program to allow you to do those things?
If so, then code says it all. Please post yours, specifically any code related to the textbox linked to the database.
-
Jan 15th, 2021, 07:02 PM
#3
Thread Starter
Junior Member
Re: I'm typing in a textbox linked to a database and it stops everything from working
It's whenever I type in a specific text box, there's no code for that text box. It's only linked to a column in Microsoft Access
-
Jan 15th, 2021, 07:09 PM
#4
Re: I'm typing in a textbox linked to a database and it stops everything from working
How much code is in the project? Is it a reasonable amount to post here, say, less than 100 lines? If so, then post all the code.
-
Jan 15th, 2021, 08:28 PM
#5
Re: I'm typing in a textbox linked to a database and it stops everything from working
In what way is it linked? We need to see the code you're using for that...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 15th, 2021, 08:45 PM
#6
Re: I'm typing in a textbox linked to a database and it stops everything from working
Originally Posted by THopwood
Title says it all
No it doesn't and it certainly shouldn't. The post should say it all and you should be writing the post first, so including things like "the title says it all" shouldn't even be a consideration. Provide a FULL and CLEAR explanation of the problem in the post. That means an explanation of exactly what you're trying to achieve, exactly how you're trying to achieve it and exactly what happens when you try. Once you have said it all in your post, then you should write a title that is a summary of that.
-
Jan 15th, 2021, 08:50 PM
#7
Re: I'm typing in a textbox linked to a database and it stops everything from working
I'm typing in a textbox linked to a database
No you're not, unless you're using a Recordset, which you shouldn't be. You need to provide actual details of what you're actually doing and then we may be able to diagnose the actual problem. TextBoxes don't prevent you doing anything for no reason. Either your system is broken or something you are doing in your project is causing the problem. You should be able to describe EXACTLY what you have done so that we can do the same thing to see whether we get the same results. You should also have done some proper testing before posting, which means starting with a new project and making changes to it step by step to make it like your existing project until it breaks. When it breaks, you know the last change you made is the problem, so you can tell us what the problem is.
-
Jan 16th, 2021, 01:39 PM
#8
Thread Starter
Junior Member
Re: I'm typing in a textbox linked to a database and it stops everything from working
Yeah I apologise, I was up late working on it and I was being lazy. I've amended the original post now with the full source code of the form to hopefully give a better understanding.
-
Jan 16th, 2021, 02:05 PM
#9
Hyperactive Member
Re: I'm typing in a textbox linked to a database and it stops everything from working
btw, in order to improve readability of your code, in text editor select all your code and press the # button.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jan 16th, 2021, 02:19 PM
#10
Thread Starter
Junior Member
Re: I'm typing in a textbox linked to a database and it stops everything from working
Thank you for that tip
-
Jan 16th, 2021, 02:28 PM
#11
Hyperactive Member
Re: I'm typing in a textbox linked to a database and it stops everything from working
You re welcome. Please rate my post.
Please dont forget to add good reputation if my advices were useful for you.
How? Under this post there is "RATE THIS POST" button. Click on it.
-
Jan 16th, 2021, 10:35 PM
#12
Re: I'm typing in a textbox linked to a database and it stops everything from working
There's various other stuff that could do with cleaning up but I see nothing that jumps out as being the cause of your specified issue. It's time for you to do some proper testing and debugging. I'd start by creating a TextChanged event handler for that TextBox and see whether it gets hit. If it does and there's still an issue, I'd delete the control and add a new one. If there's still an issue, I'd create a new project and build it up in stages until it is the same as your current project or the same issue occurs. If the former then it's an issue with that project specifically. If the latter then you know exactly what change caused the issue to manifest and, if nothing else, you can provide us with that information.
-
Jan 16th, 2021, 10:38 PM
#13
Re: I'm typing in a textbox linked to a database and it stops everything from working
By the way, you should turn Option Strict On in the project properties and DO NOT turn it Off at the file level except in the rare circumstances that you need to use late binding. You should also turn it On in the VS options, so it is On by default for all future projects. Unless you need late binding, turning Option Strict Off is a lazy way to hide problems and avoid your responsibilities as a developer, i.e. to always know what data type you're using and why. Even when you do need late binding, it should still be On at the project level and turned Off in only the files that require it. Even then, partial classes should be used to keep the code in those files to an absolute minimum.
Last edited by jmcilhinney; Jan 16th, 2021 at 11:06 PM.
-
Jan 16th, 2021, 10:44 PM
#14
Re: I'm typing in a textbox linked to a database and it stops everything from working
I don't see any code that involves the CustomerID Textbox. Is this textbox on the body of the form or is it part of the ToolStrip? Does it lockup as soon as you type the first character in the Textbox. Does the Textbox keep focus.
Also you have no Handles clause here,
Code:
Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs)
This doesn't make sense,
Code:
Try
Catch ex As Exception
MessageBox.Show("There was an error when Searching." & ex.Message.ToString(),
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
-
Jan 18th, 2021, 11:48 AM
#15
Thread Starter
Junior Member
Re: I'm typing in a textbox linked to a database and it stops everything from working
Originally Posted by wes4dbt
I don't see any code that involves the CustomerID Textbox. Is this textbox on the body of the form or is it part of the ToolStrip? Does it lockup as soon as you type the first character in the Textbox. Does the Textbox keep focus.
Also you have no Handles clause here,
Code:
Private Sub FillByToolStripButton_Click(sender As Object, e As EventArgs)
This doesn't make sense,
Code:
Try
Catch ex As Exception
MessageBox.Show("There was an error when Searching." & ex.Message.ToString(),
"Glorious Getaways", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
I've fixed it now, the CustomerID textbox was set to an integer instead of a String like I wanted and the max value was -1 for some reason, I have changed that now. And the second piece of code just displays a messagebox whenever there has been an exception when searching. I still need to add the code for searching.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|