Not sure if I spelled **** the right way or not. I meant the thing that holds back water. Ok, whatever.
Alright. I got this form with some textboxes on it. I've also got this Access database created to hold the values of these textboxes. My goal...when a registered user to my DNN site goes to the page that has this form (which part of my custom module)...the textboxes will be populated with info from the database (assuming this user has saved info into the database already). Additionally, the user can edit the textboxes and save the changes to the database. The database has the userid (generated by DNN for that user) and several other fields corresponding to the textbox information.
So why plugging holes? Because I have programmed procedures for the page_load and procedures for a the button_click (which is displayed next to the textboxes which says "Click to Save Changes"). So far, depending on how I position a dataset.clear() I can either:
A. Have the page initially load and display the user's saved database info into the textboxes (which I want)
OR
B. Have the button_click succesfully update the contents of the database
But I can't do both. Both functions work...just not at the same time. Which works when? Depends on where I put the dataset.clear() in the page_load. I'm not sure why, though. I've posted the code for both the page_load and the button_click events in the hopes that somebody can point out my errors. Thanks for any help you can provide.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Put in code that first checks to see if this is a registerd user and if so:
' Opens the AircraftProfile.mdb and checks to see if userid exists and if so:
' Loads the user's info and populates the textboxes accordingly
Dim IobjUsers As New UserController
Dim IobjUser As UserInfo
Dim Isregistered As Boolean
Isregistered = True
Try
IobjUser = IobjUsers.GetUser(PortalId, Int32.Parse(context.User.Identity.Name))
' the above works ONLY if it's a registered user...otherwise it returns an error
Catch ex As Exception
Isregistered = False
End Try
If Isregistered Then
Dim IOurUserID As String
If Not IobjUser Is Nothing Then
IOurUserID = IobjUser.UserID.ToString
End If
Dim IAIR_PROdb As New OleDb.OleDbConnection
Dim IGetAIR_PRO As New OleDb.OleDbCommand
Dim IAIR_PROAdapter As New OleDb.OleDbDataAdapter
Dim IAIR_PROds As New DataSet
Try
IAIR_PROdb.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataSourcePath & "aircraftprofile.mdb"
IGetAIR_PRO.CommandText = "Select * from AIR_PROFILE WHERE user_id='" & IOurUserID & "'"
IGetAIR_PRO.Connection = IAIR_PROdb
IAIR_PROAdapter.SelectCommand = IGetAIR_PRO
IAIR_PROdb.Open()
Catch ex As Exception
SysError = True
ErrorRpt &= "***There was a problem accessing the Aircraft Profile database on Flight Plan page load: " & ex.ToString
End Try
Try
IAIR_PROAdapter.Fill(IAIR_PROds, "AIR_PROFILE")
IAIR_PROdb.Close()
Catch ex As Exception
SysError = True
ErrorRpt &= "***There was a problem filling the dataset from the Aircraft Profile database on Flight Plan page load: " & ex.ToString
End Try
Dim IAIR_PROtable As New DataTable
IAIR_PROtable = IAIR_PROds.Tables("AIR_PROFILE")
If IAIR_PROtable.Rows.Count = 0 Then Return 'cuz no profile saved yet
Textbox19.Text = IAIR_PROtable.Rows(0)(1) 'fill TAS
TextBox7.Text = IAIR_PROtable.Rows(0)(2) 'operating weight
TextBox8.Text = IAIR_PROtable.Rows(0)(3) 'fuel load
Dropdownlist2.SelectedIndex = IAIR_PROtable.Rows(0)(4) 'Aircraft Category
Textbox4.Text = IAIR_PROtable.Rows(0)(5) 'Min Departure Rwy Length
Textbox9.Text = IAIR_PROtable.Rows(0)(6) 'Min Arrival Rwy Length
Textbox5.Text = IAIR_PROtable.Rows(0)(7) 'Min Rwy Width
Textbox6.Text = IAIR_PROtable.Rows(0)(8) 'Max Crosswind
DropDownList1.SelectedIndex = IAIR_PROtable.Rows(0)(9) 'Aircraft Type
Textbox20.Text = IAIR_PROtable.Rows(0)(10) 'Burn Rate
IAIR_PROds.Clear() 'PUT IT HERE-initial load works but won't update user profile
IAIR_PROtable.Clear()
End If 'if is registered
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
' Put in code that checks to see if the user already has info in the aircraftprofile.mdb
' and saves over the info already in it...or creates a new record using the userid and
' fills in the fields with info from textboxes
Dim objUsers As New UserController
Dim objUser As UserInfo
Try
objUser = objUsers.GetUser(PortalId, Int32.Parse(context.User.Identity.Name))
' the above works ONLY if it's a registered user...otherwise it returns an error
Catch ex As Exception
' the user is NOT registered
Label3.Text = "YOU MUST FIRST LOGIN OR REGISTER TO MAKE AN AIRCRAFT PROFILE"
Label3.Visible = True
Return
End Try
Label3.Visible = False
Dim OurUserID As String
If Not objUser Is Nothing Then
OurUserID = objUser.UserID.ToString
End If
Dim AIR_PROdb As New OleDb.OleDbConnection
Dim GetAIR_PRO As New OleDb.OleDbCommand
Dim AIR_PROAdapter As New OleDb.OleDbDataAdapter
Dim AIR_PROds As New DataSet
Try
AIR_PROdb.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataSourcePath & "aircraftprofile.mdb"
GetAIR_PRO.CommandText = "Select * from AIR_PROFILE WHERE user_id='" & OurUserID & "'"
GetAIR_PRO.Connection = AIR_PROdb
AIR_PROAdapter.SelectCommand = GetAIR_PRO
AIR_PROdb.Open()
Catch ex As Exception
SysError = True
ErrorRpt &= "***There was a problem accessing the Aircraft Profile database: " & ex.ToString
End Try
Try
AIR_PROAdapter.Fill(AIR_PROds, "AIR_PROFILE")
Catch ex As Exception
SysError = True
ErrorRpt &= "***There was a problem filling the dataset from the Aircraft Profile database: " & ex.ToString
End Try
Dim AIR_PROtable As DataTable = AIR_PROds.Tables("AIR_PROFILE")
Dim mytas, myopweight, myfuel, mymindlength, myminalength, myminwidth, mymaxcross, myburn, myaircat, myairtype As Integer 'going to use the index values for the dropdownlists...
mytas = Textbox19.Text
myopweight = TextBox7.Text
myfuel = TextBox8.Text
mymindlength = Textbox4.Text
myminalength = Textbox9.Text
myminwidth = Textbox5.Text
mymaxcross = Textbox6.Text
myburn = Textbox20.Text
myaircat = Dropdownlist2.SelectedIndex
myairtype = DropDownList1.SelectedIndex
If AIR_PROtable.Rows.Count = 0 Then
' First time user has saved a profile
GetAIR_PRO.CommandText = "Insert into AIR_PROFILE(User_Id,tas,op_weight,fuel_load,air_cat,min_dpt_length,min_arr_length,min_width,max_cross,air_type,burn_rate) values (" & OurUserID & "," & mytas & "," & myopweight & "," & myfuel & "," & myaircat & "," & mymindlength & "," & myminalength & "," & myminwidth & "," & mymaxcross & "," & myairtype & "," & myburn & ")"
ElseIf AIR_PROtable.Rows.Count = 1 Then
' He's updating already existing info
GetAIR_PRO.CommandText = "UPDATE AIR_PROFILE SET tas='" & mytas & "', op_weight = '" & myopweight & "', fuel_load = '" & myfuel & "', air_cat = '" & myaircat & "', min_dpt_length = '" & mymindlength & "', min_arr_length = '" & myminalength & "', min_width = '" & myminwidth & "', max_cross = '" & mymaxcross & "', air_type = '" & myairtype & "', burn_rate = '" & myburn & "' WHERE user_id = '" & OurUserID & "'"
Else
SysError = True
ErrorRpt &= "User tried to edit Aircraft Profile and while searching for UserID in database found more than one userid. "
Return
End If
GetAIR_PRO.ExecuteNonQuery() 'now that the proper command has been made...execute it
' CLEAN UP
AIR_PROdb.Close()
AIR_PROds.Clear()
AIR_PROtable.Clear()
End Sub