Evenjelith
Registered User.
- Local time
- Tomorrow, 03:28
- Joined
- Jul 14, 2008
- Messages
- 11
Hi, my boss wants me to fix up the company database; adding a button which puts a new table entry provided by the user into the database. I have all the necessary forms I require but the problem is my VB code. I've pillaged some code from other threads on this site and tried to rework it for the job i've been given but I keep getting exceptions. First i was getting that a user variable was undefined or something like that and now im getting expected end of statement.
The compiler HATES the Handles addWellButton.click at the end and i have no idea what it's needed for but it's been in quite a few examples ive looked at for this kind of problem so if someone could tell me what it is that would be great.
The user enters a well name in a text box and then hits the add button. The text is then passed into a new row in the table and all other columns are given a null value.
Any help at all would be hugely appreciated!
Here's the code I'm using:
Private Sub addWellButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addWellButton.Click
Dim Conn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=F:\WELLS\Database\Database.mdb;User Id=;Password=;"
Dim tConnection As New OleDb.OleDbConnection(Conn)
Dim SQL As String = "INSERT INTO Wells Database ([Well Name-#], Type, Result, Status, Surveyed, Drilling Contractor, Precollar Rig, Rig, Shift Duration, Spud Date, TD Date, Plugged Back TD, Rig Release Date, Lot and Plan, Comments, Days Offsite) VALUES(@[Well Name-#], null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)"
Dim tCommand As New OleDb.OleDbCommand(SQL, tConnection)
WellName = txtAddWellName.Value
If (IsNull(WellName)) Then
MsgBox ("Please enter a well name"), vbOKOnly, "Re-enter"
Else
With tCommand
.Parameters.Add("@[Well Name-#]", OleDb.OleDbType.VarChar)
.Parameters(0).Value = txtAddWellName.Text
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
End With
MsgBox (WellName + " added to database"), vbOKOnly, "Well Added"
End If
End Sub
The compiler HATES the Handles addWellButton.click at the end and i have no idea what it's needed for but it's been in quite a few examples ive looked at for this kind of problem so if someone could tell me what it is that would be great.
The user enters a well name in a text box and then hits the add button. The text is then passed into a new row in the table and all other columns are given a null value.
Any help at all would be hugely appreciated!
Here's the code I'm using:
Private Sub addWellButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addWellButton.Click
Dim Conn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=F:\WELLS\Database\Database.mdb;User Id=;Password=;"
Dim tConnection As New OleDb.OleDbConnection(Conn)
Dim SQL As String = "INSERT INTO Wells Database ([Well Name-#], Type, Result, Status, Surveyed, Drilling Contractor, Precollar Rig, Rig, Shift Duration, Spud Date, TD Date, Plugged Back TD, Rig Release Date, Lot and Plan, Comments, Days Offsite) VALUES(@[Well Name-#], null, null, null, null, null, null, null, null, null, null, null, null, null, null, null)"
Dim tCommand As New OleDb.OleDbCommand(SQL, tConnection)
WellName = txtAddWellName.Value
If (IsNull(WellName)) Then
MsgBox ("Please enter a well name"), vbOKOnly, "Re-enter"
Else
With tCommand
.Parameters.Add("@[Well Name-#]", OleDb.OleDbType.VarChar)
.Parameters(0).Value = txtAddWellName.Text
.Connection.Open()
.ExecuteNonQuery()
.Connection.Close()
End With
MsgBox (WellName + " added to database"), vbOKOnly, "Well Added"
End If
End Sub