Creating a new item or updating an existing item

voleweemi

New Member
Something about my code just doesn't seem right. It feels cumbersome and not very logical.Could someone put me out of my misery and let me know that I wrote this bit ok?It's pretty simple, when the page loads, it is checking to see if the user is trying to update an existing book or create a new book.Here is the code:\[code\]Public Property modID As Int32Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadDim bookID = Request.QueryString("bookID")If Not String.IsNullOrWhiteSpace(bookID) Then newBook = False Else newBook = True Create() 'create a new book bookID = modID.ToString End If If Not newBook Then commitData() 'saves data on form End If If Not IsPostBack And Not newBook Then Page.DataBind() populateControls() 'populate my dropdown lists and radio/checkbox controls populateDatasets() 'load datasets to be used later End If\[/code\]End Sub\[code\]Public Sub Create() 'create a new book newBook = False Using dbcon As New SqlConnection(DBUtilities.ConnectionStringDefault) dbcon.Open() Dim cmd As New SqlCommand(CreateSQL, dbcon) cmd.Parameters.Add(New SqlParameter("@authorID", currentUser)) modID = DirectCast(cmd.ExecuteScalar(), Int32) End Using navmod = NavbookFactory.Getbook(CInt(modID)) populateNewBook()End Sub\[/code\]
 
Back
Top