Made alot of Progress but still isnt saving

Two Errors but cant figure out how to fix

Page 1 of 1

8 Replies - 779 Views - Last Post: 09 November 2008 - 10:45 PM Rate Topic: -----

#1 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Made alot of Progress but still isnt saving

Post icon  Posted 08 November 2008 - 10:35 AM

Now I've gotten part of the errors fixed but the Form Still isnt saving to the Database:

Posted Image

The Update Button does nothing. The save Button will inset the new record into the combo box and make the controls read only, but the will not save to database. It also locks the form completely, cannot exit without closing form. When I pull it back up no record is saved. I have came a long way though. No errors on the forms code.

'SienaSantolina
'Capstone
Imports System.Data


Public Class CamperMaintenanceForm
	Private aCamperDataTier As New CamperDataTier
	Private aYouthCampDataSet As YouthCampDataSet
	Private WithEvents aCamperBindingSource As BindingSource

	'1

	Private addingBoolean As Boolean = False
	Private editingBoolean As Boolean = False
	Private closingBoolean As Boolean = False
	Private previousSelectedIndex As Integer
	Private setupCompleteBoolean As Boolean = False
	Private Shared anInstance As CamperMaintenanceForm
	Public Shared ReadOnly Property Instance() As CamperMaintenanceForm

		Get
			If anInstance Is Nothing Then
				anInstance = New CamperMaintenanceForm
			End If
			Return anInstance
		End Get
	End Property
	Private Sub GroupBox4_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CamperInfoBox.Enter

	End Sub


	Private Sub CamperNameLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles camperNameLabel.Click

	End Sub

	Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles parentLastNameTextBox.TextChanged

	End Sub

	Private Sub homeChurchLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles churchNameLabel.Click

	End Sub

	Private Sub CamperMaintenanceForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
		Try


			With Me
				'Create an instance of the data-tier component.
				aCamperDataTier = New CamperDataTier
				'Retrieve the dataSet from the data tier.
				aYouthCampDataSet = aCamperDataTier.GetDataSet

				'Set up the Binding Source
				.aCamperBindingSource = New BindingSource
				With .aCamperBindingSource
					.DataSource = Me.aYouthCampDataSet
					.DataMember = "camper"
					.Sort = "LastName"
				End With


				'Bind the controls
				'needs to be updated with FULL NAME and Possibly DataSourceUpdate to allow?
				'check fields of zip, number etc
				'need a allergy, medications, parentsFirstName, ParentsLastName, exceptions field on table
				'do we need an age? birthday? on table?
				'PastorName, ChurchPhoneNumber on Churches Table
				'City State Zip pulled from CITYSTATEZIPTABLE
				With .CamperComboBox
					.DataSource = Me.aCamperBindingSource
					.DisplayMember = "LastName"
					.DataBindings.Add("text", aCamperBindingSource, "LastName", _
					False, DataSourceUpdateMode.Never)
				End With
				.firstNameTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "FirstName", False, DataSourceUpdateMode.OnValidation)
				.lastNameTextBox.DataBindings.Add("text", _
				 .aCamperBindingSource, "LastName", False, DataSourceUpdateMode.OnValidation)
				.streetTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "StreetAddress", False, DataSourceUpdateMode.OnValidation)
				.cityTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "City", False, DataSourceUpdateMode.OnValidation)
				.stateTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "State", False, DataSourceUpdateMode.OnValidation)
				'cant bind at zip?
				.zipCodeTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "Zip", False, DataSourceUpdateMode.OnValidation)

				.camperPhoneNumberTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "PhoneNumber", Nothing, False, DataSourceUpdateMode.OnValidation)
				.allergiesTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "Allergies", Nothing, False, DataSourceUpdateMode.OnValidation)
				.medicationsTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "Medications", Nothing, False, DataSourceUpdateMode.OnValidation)
				.activityExemptionTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "Exemptions", Nothing, False, DataSourceUpdateMode.OnValidation)
				.parentFirstnameTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "ParentFirstName", False, DataSourceUpdateMode.OnValidation)
				.parentLastNameTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "ParentLastName", False, DataSourceUpdateMode.OnValidation)
				.homeNumberTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "GuardianPhoneNumberH", Nothing, False, DataSourceUpdateMode.OnValidation)
				.workNumberTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "GuardianPhoneNumberW", Nothing, False, DataSourceUpdateMode.OnValidation)
				.cellPhoneTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "GuardianPhoneNumberC", Nothing, False, DataSourceUpdateMode.OnValidation)
				.AgeTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "Age", False, DataSourceUpdateMode.OnValidation)
				.birthDateTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "Birthday", False, DataSourceUpdateMode.OnValidation, "d")
				.homeChurchTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "ChurchName", Nothing, False, DataSourceUpdateMode.OnValidation)
				.pastorNameTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "PastorName", Nothing, False, DataSourceUpdateMode.OnValidation)
				.churchNumberTextBox.DataBindings.Add("text", _
				.aCamperBindingSource, "ChurchPhoneNumber", Nothing, False, DataSourceUpdateMode.OnValidation)


			End With

			'displays date in status bar-useful for adding campers
			With Me
				DateToolStripStatusLabel.Text = Now.ToShortDateString
				TimeToolStripStatusLabel.Text = Now.ToLongTimeString
			End With
		Catch ex As Exception
			MessageBox.Show("Error Creating the data tier component " & ex.Message)
		End Try

	End Sub

	Private Sub CamperMaintenanceForm_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
		Me.CamperComboBox.Focus()
	End Sub
	Private Sub CamperMaintenanceForm_FormClosing(ByVal sender As Object, _
	ByVal e As System.Windows.Forms.FormClosingEventArgs) _
	Handles Me.FormClosing
		Dim responseDialogResult As DialogResult
		With Me
			.closingBoolean = True
			If .aYouthcampDataSet.HasChanges Then
				responseDialogResult = MessageBox.Show("Save the database Changes?", _
				"Changed Data", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
				Select Case responseDialogResult
					Case Windows.Forms.DialogResult.Yes
						.saveDataSet()
					Case Windows.Forms.DialogResult.Cancel
						e.Cancel = True
				End Select
			End If
		End With
		'Release the instance of this form
		anInstance = Nothing
		e.Cancel = False
	End Sub

	Private Sub DateToolStripStatusLabel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateToolStripStatusLabel.Click

	End Sub

	Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
		With Me
			.DateToolStripStatusLabel.Text = Now.ToShortDateString()
			.TimeToolStripStatusLabel.Text = Now.ToLongTimeString()

		End With
	End Sub

	Private Sub firstNameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles firstNameTextBox.TextChanged

	End Sub

	Private Sub firstNameTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles firstNameTextBox.Validating
		'validate for a required entry
		'cancel any previous error
		ErrorProvider1.SetError(firstNameTextBox, "")

		With Me.firstNameTextBox
			If .Text = String.Empty Then
				'cancel the event
				e.Cancel = True
				ErrorProvider1.SetError(firstNameTextBox, "Required.")
			End If

		End With
	End Sub

	Private Sub lastNameTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles lastNameTextBox.Validating
		'validate for a required entry
		'cancel any previous error
		ErrorProvider1.SetError(lastNameTextBox, "")

		With Me.lastNameTextBox
			If .Text = String.Empty Then
				'cancel the event
				e.Cancel = True
				ErrorProvider1.SetError(lastNameTextBox, "Required.")
			End If

		End With
	End Sub

	Private Sub streetTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles streetTextBox.TextChanged

	End Sub

	Private Sub streetTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles streetTextBox.Validating
		'validate for a required entry
		'cancel any previous error
		ErrorProvider1.SetError(streetTextBox, "")

		With Me.streetTextBox
			If .Text = String.Empty Then
				'cancel the event
				e.Cancel = True
				ErrorProvider1.SetError(streetTextBox, "Required.")
			End If

		End With
	End Sub

	Private Sub cityTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cityTextBox.Validating
		'validate for a required entry
		'cancel any previous error
		ErrorProvider1.SetError(cityTextBox, "")

		With Me.cityTextBox
			If .Text = String.Empty Then
				'cancel the event
				e.Cancel = True
				ErrorProvider1.SetError(cityTextBox, "Required.")
			End If

		End With
	End Sub

	Private Sub stateTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles stateTextBox.Validating
		'cancel any previous error
		ErrorProvider1.SetError(stateTextBox, "")

		With Me.stateTextBox
			If .Text.Length <> 2 Then
				'cancel the event and select the text.
				e.Cancel = True
				.SelectAll()
				ErrorProvider1.SetError(stateTextBox, "Must be 2 Characters.")
			End If
		End With
	End Sub

	Private Sub parentFirstnameTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles parentFirstnameTextBox.Validating
		'validate for a required entry
		'cancel any previous error
		ErrorProvider1.SetError(parentFirstnameTextBox, "")

		With Me.parentFirstnameTextBox
			If .Text = String.Empty Then
				'cancel the event
				e.Cancel = True
				ErrorProvider1.SetError(parentFirstnameTextBox, "Required.")
			End If

		End With
	End Sub

	Private Sub parentLastNameTextBox_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles parentLastNameTextBox.Validating
		'validate for a required entry
		'cancel any previous error
		ErrorProvider1.SetError(parentLastNameTextBox, "")

		With Me.parentLastNameTextBox
			If .Text = String.Empty Then
				'cancel the event
				e.Cancel = True
				ErrorProvider1.SetError(parentLastNameTextBox, "Required.")
			End If

		End With
	End Sub

	Private Sub exitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitBtn.Click
		Me.Close()
	End Sub

	Private Sub exitBtn_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles exitBtn.Validating
		e.Cancel = False
	End Sub

	Private Sub CamperComboBox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles CamperComboBox.KeyDown
		'handles the escape key while editing and adding
		With Me
			If (.addingBoolean Or .editingBoolean) And _
			e.KeyData = Keys.Escape Then
				.cancelAddOrEdit()
			End If
		End With
	End Sub

	Private Sub CamperComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CamperComboBox.SelectedIndexChanged
		'here I may need a method to fill the text boxes from the combo box?
	End Sub

	Private Sub addCamperBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addCamperBtn.Click
		'Begin An Add Operation
		Try
			With Me.aCamperBindingSource
				.EndEdit()
				.AddNew()

			End With
			With Me
				.addingBoolean = True
				.setComboBoxBinding()
				.setControlsReadOnly(False)

				If .CamperComboBox.SelectedIndex <> -1 Then
					'Save the index of the new record for later navigation.
					.previousSelectedIndex = .CamperComboBox.Items.Count - 1
				Else
					.previousSelectedIndex = 0
				End If

			End With
		Catch ex As Exception
			MessageBox.Show("Error on AddNew: " & ex.Message)
		End Try
	End Sub
	
	
	Private Sub CamperComboBox_SelectionchangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles CamperComboBox.SelectionchangeCommitted

	End Sub

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

	End Sub

	Private Sub CamperBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
		Me.Validate()
		Me.aCamperBindingSource.EndEdit()

	End Sub

	Private Sub updateCamperBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles updateCamperBtn.Click

	End Sub

	Private Sub SaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveButton.Click
		'save Updates and Adds to the DataSet
		With Me

			.ErrorProvider1.Clear()
			.CamperBindingSource.EndEdit()
			.addingBoolean = False
			.editingBoolean = False
			.setControlsReadOnly(True)
			.resetbuttonsAfterEdit()
			.setComboBoxBinding()
			.CamperComboBox.SelectedIndex = .previousSelectedIndex
			.CamperTableAdapter.Fill(YouthCampDataSet.Camper)

		End With
	End Sub

	

	'procedures
	Private Sub CancelAddOrEdit()
		'cancel add or edit
		' called from the cancel button
		With Me
			If .addingBoolean Then
				.previousSelectedIndex -= 1
			End If
			.aCamperBindingSource.CancelEdit()
			.addingBoolean = False
			.editingBoolean = False
			.setControlsReadOnly(True)
			.resetbuttonsAfterEdit()
			.setComboBoxBinding()
			.CamperComboBox.SelectedIndex = .previousSelectedIndex
			.ErrorProvider1.Clear()
		End With
	End Sub
	Private Sub resetButtonsAfterEdit()
		'reset the buttons after edit
		With Me
			.updateCamperBtn.Enabled = False
			.addCamperBtn.Enabled = False
			.SaveButton.Enabled = False
			.CancelButton.Enabled = False
			.exitBtn.Enabled = False
		End With
	End Sub
	Private Sub saveDataSet()
		'Save the DataSet to the original data source

		With Me
			If .aYouthCampDataSet.HasChanges Then
				Try
					.Validate()
					.aCamperBindingSource.EndEdit()
					.aCamperDataTier.UpdateDataSet(.aYouthCampDataSet)
					.aYouthCampDataSet.AcceptChanges()

				Catch ex As Exception
					MessageBox.Show("Unable to save Complete Operation. " & ex.Message)
				End Try
			End If
		End With
	End Sub
	Private Sub setButtonsForEdit()
		' sets the buttons for an Add or Edit
		With Me
			.CancelButton.Enabled = True
			.SaveButton.Enabled = True
			If .addingBoolean Then
				.StatusStrip2.Text = "Adding"
			Else
				.StatusStrip2.Text = "Editing"
			End If
		End With
	End Sub
	Private Sub setComboBoxBinding()
		'Set the combo box to save any changes
		'Saves for Add or Edit, does not save during navigation
		'Sets the combo box to not allow drop-down during and Add or Edit

		With Me.CamperComboBox
			If (addingBoolean Or editingBoolean) Then
				.DataBindings!text.DataSourceUpdateMode = DataSourceUpdateMode.OnValidation
				.DropDownStyle = ComboBoxStyle.Simple
			Else
				.DataBindings!text.DataSourceUpdateMode = DataSourceUpdateMode.Never
				.DropDownStyle = ComboBoxStyle.DropDownList
			End If
		End With
	End Sub
	Private Sub setControlsReadOnly(ByVal valueBoolean As Boolean)
		'Lock or unlock the contorls

		With Me
			.firstNameTextBox.ReadOnly = valueBoolean
			.lastNameTextBox.ReadOnly = valueBoolean
			.streetTextBox.ReadOnly = valueBoolean
			.cityTextBox.ReadOnly = valueBoolean
			.stateTextBox.ReadOnly = valueBoolean
			.zipCodeTextBox.ReadOnly = valueBoolean
			.camperPhoneNumberTextBox.ReadOnly = valueBoolean
			.parentFirstnameTextBox.ReadOnly = valueBoolean
			.parentLastNameTextBox.ReadOnly = valueBoolean
			.homeNumberTextBox.ReadOnly = valueBoolean
			.workNumberTextBox.ReadOnly = valueBoolean
			.cellPhoneTextBox.ReadOnly = valueBoolean
			.homeChurchTextBox.ReadOnly = valueBoolean
			.pastorNameTextBox.ReadOnly = valueBoolean
			.churchNumberTextBox.ReadOnly = valueBoolean
			.AgeTextBox.ReadOnly = valueBoolean
			.birthDateTextBox.ReadOnly = valueBoolean

		End With
	End Sub

	

	Private Sub CamperBindingSource_Positionchanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CamperBindingSource.Positionchanged

	End Sub

End Class

The data access(tier) Class has two errors in the "UpdateDataSet":
aCamperTableAdapter.Update(camperDeleteDataTable)
aCamperTableAdapter.Update(camperDeleteDataTable)
There is an error at "Update" on both saying "its not a member of YouthCampTableSetTableAdapters.CamperTableAdapter. This is the Code:

[code]Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Imports System.Configuration.ConfigurationSettings

Public Class CamperDataTier
'Declare class level variables
Private aCamperTableAdapter As YouthCampDataSetTableAdapters.CamperTableAdapter
Private aCamperToCampRelation As DataRelation
Private aYouthCampDataSet As YouthCampDataSet

Public Sub New()
Try
With Me
'instantiate the TableAdapters and DataSet.
.aCamperTableAdapter = New YouthCampDataSetTableAdapters.CamperTableAdapter()
.aYouthCampDataSet = New YouthCampDataSet
.aCamperToCampRelation = .aYouthCampDataSet.Relations!CamperToStoresRelation

'fill the dataset
.aCamperTableAdapter.Fill(.aYouthCampDataSet.Camper)
End With
Catch ex As Exception
Throw ex
End Try
End Sub
Public Function GetDataSet() As YouthCampDataSet
'return the dataset
Return aYouthCampDataSet
End Function

Public Sub UpdateDataSet(ByVal aDataSet As YouthCampDataSet)

'Save all updates to the original data source
Try

'Update child deletes
If aDataSet.Counselor.GetChanges(DataRowState.Deleted) _
IsNot Nothing Then
'Get changes for the deleted child rows only.
Dim camperDeleteDataTable As DataTable
camperDeleteDataTable = aDataSet.Camper.GetChanges(DataRowState.Deleted)
aCamperTableAdapter.Update(camperDeleteDataTable)
End If

'update all parent row Adds, Deletes and Edits.
If aDataSet.Camper.GetChanges(DataRowState.Added + DataRowState.Modified) _
IsNot Nothing Then
'get changes for the added and changed rows only
Dim camperAddDataTable As DataTable
camperAddDataTable = aDataSet.Camper.GetChanges(DataRowState.Added + DataRowState.Modified)
Me.aCamperTableAdapter.Update(camperAddDataTable)
End If

Catch ex As Exception
Throw ex
End Try
End Sub

'Sql stuff pulled from Tutorial on DIC
'dont know if any of this is helping at all

''' <summary>
''' Returns a BindingSource, which is used with, for example, a DataGridView control
''' </summary>
''' <param name="cmd">"pre-Loaded" command, ready to be executed</param>
''' <returns>BindingSource</returns>
''' <remarks>Use this function to ease populating controls that use a BindingSource</remarks>
Public Shared Function GetBindingSource(ByVal cmd As SqlCommand) As BindingSource
'declare our binding source
Dim oBindingSource As New BindingSource()
' Create a new data adapter based on the specified query.
Dim daGet As New SqlDataAdapter(cmd)
' Populate a new data table and bind it to the BindingSource.
Dim dtGet As New DataTable()
'set the timeout of the SqlCommandObject
cmd.CommandTimeout = 240
dtGet.Locale = System.Globalization.CultureInfo.InvariantCulture
Try
'fill the DataTable with the SqlDataAdapter
daGet.Fill(dtGet)
Catch ex As Exception
'check for errors
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error receiving data")
Return Nothing
End Try
'set the DataSource for the BindingSource to the DataTable
oBindingSource.DataSource = dtGet
'return the BindingSource to the calling method or control
Return oBindingSource
End Function
''' <summary>
''' Method for handling the ConnectionState of
''' the connection object passed to it
''' </summary>
''' <param name="conn">The SqlConnection Object</param>
''' <remarks></remarks>
Public Shared Sub HandleConnection(ByVal conn As SqlConnection)
With conn
'do a switch on the state of the connection
Select Case .State
Case ConnectionState.Open
'the connection is open
'close then re-open
.Close()
.Open()
Exit Select
Case ConnectionState.Closed
'connection is open
'open the connection
.Open()
Exit Select
Case Else
.Close()
.Open()
Exit Select
End Select
End With
End Sub

'procedures for passing variables from sql
Public Shared Function InsertNewRecord(ByVal item1 As String, ByVal item2 As String, ByVal item3 As String) As Boolean
'If not using the Express Edition uncomment the next line
'Dim cnInsert As New SqlConnection(GetConnectionString("YourConnName"))
'If using Express Edition uncomment the next line
Dim cnInsert As New SqlConnection("F:\YouthCamp(CapStone FINAL)\YouthCamp(CapStone)\YouthCamp.mdf")
Dim cmdInsert As New SqlCommand
Dim sSQL As New String("")
Dim iSqlStatus As Integer

'Set the stored procedure we're going to execute
sSQL = "YourProcName"

'Inline sql needs to be structured like so
'sSQL = "INSERT INTO YourTable(column1,column2,column3) VALUES('" & item1 & "','" & item2 & "','" & item3 & "')"

'Clear any parameters
cmdInsert.Parameters.Clear()
Try
'Set the SqlCommand Object Properties
With cmdInsert
'Tell it what to execute
.CommandText = sSQL 'Your sql statement
'Tell it its a stored procedure (if using inline sql uncomment this line
'.CommandType = CommandType.StoredProcedure 'CommandType.Text for inline sql
'If you arent using a stored procedure uncomment the next line
'.CommandType = CommandType.StoredProcedure 'For inline sql
'If you are indeed using a stored procedure
'the next 3 lines pertain to you
'Now add the parameters to our procedure
'NOTE: Replace @value1.... with your parameter names in your stored procedure
'and add all your parameters in this fashion
.Parameters.AddWithValue("@value1", item1)
.Parameters.AddWithValue("@value2", item2)
.Parameters.AddWithValue("@value3", item3)
'Set the connection of the object
.Connection = cnInsert
End With

'Now take care of the connection
HandleConnection(cnInsert)

'Set the iSqlStatus to the ExecuteNonQuery
'status of the insert (0 = success, 1 = failed)
iSqlStatus = cmdInsert.ExecuteNonQuery

'Now check the status
If Not iSqlStatus = 0 Then
'DO your failed messaging here
Return False
Else
'Do your success work here
Return True
End If
Catch ex As Exception
MsgBox("ex.Message,MsgBoxStyle.OkOnly", "Error")
Finally
'Now close the connection
HandleConnection(cnInsert)
End Try
End Function


Public Shared Function UpdateRecord(ByVal item1 As String, ByVal item2 As String, ByVal id As Integer) As Boolean
'If not using the Express Edition uncomment the next line
'Dim cnInsert As New SqlConnection(GetConnectionString("YourConnName"))
'If using Express Edition uncomment the next line
Dim cnInsert As New SqlConnection("F:\YouthCamp(CapStone FINAL)\YouthCamp(CapStone)\YouthCamp.mdf")
Dim cmdUpdate As New SqlCommand
Dim sSQL As New String("")
Dim iSqlStatus As Integer

'Set the stored procedure we're going to execute
sSQL = "YourProcName"

'Inline sql needs to be structured like so
'sSQL = "UPDATE YourTable SET column1 = '" & item1 & "',column2 = '" & item2 & "' WHERE YourId = " & id

'Clear any parameters
cmdUpdate.Parameters.Clear()
Try
'Set the SqlCommand Object Properties
With cmdUpdate
'Tell it what to execute
.CommandText = sSQL 'Your sql statement
'Tell it its a stored procedure (if using inline sql uncomment this line
 

Attached File(s)


This post has been edited by absynthe: 08 November 2008 - 03:41 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Made alot of Progress but still isnt saving

#2 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Made alot of Progress but still isnt saving

Posted 08 November 2008 - 11:40 AM

This is the data tier, all of it wont post above?

Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Imports System.Configuration.ConfigurationSettings

Public Class CamperDataTier
	'Declare class level variables
	Private aCamperTableAdapter As YouthCampDataSetTableAdapters.CamperTableAdapter
	Private aCamperToCampRelation As DataRelation
	Private aYouthCampDataSet As YouthCampDataSet

	Public Sub New()
		Try
			With Me
				'instantiate the TableAdapters and DataSet.
				.aCamperTableAdapter = New YouthCampDataSetTableAdapters.CamperTableAdapter()
				.aYouthCampDataSet = New YouthCampDataSet
				.aCamperToCampRelation = .aYouthCampDataSet.Relations!CamperToStoresRelation

				'fill the dataset
				.aCamperTableAdapter.Fill(.aYouthCampDataSet.Camper)
			End With
		Catch ex As Exception
			Throw ex
		End Try
	End Sub
	Public Function GetDataSet() As YouthCampDataSet
		'return the dataset
		Return aYouthCampDataSet
	End Function

	Public Sub UpdateDataSet(ByVal aDataSet As YouthCampDataSet)

		'Save all updates to the original data source
		Try
			
			'Update child deletes
			If aDataSet.Counselor.GetChanges(DataRowState.Deleted) _
			IsNot Nothing Then
				'Get changes for the deleted child rows only.
				Dim camperDeleteDataTable As DataTable
				camperDeleteDataTable = aDataSet.Camper.GetChanges(DataRowState.Deleted)
				aCamperTableAdapter.Update(camperDeleteDataTable)
			End If

			'update all parent row Adds, Deletes and Edits.
			If aDataSet.Camper.GetChanges(DataRowState.Added + DataRowState.Modified) _
			IsNot Nothing Then
				'get changes for the added and changed rows only
				Dim camperAddDataTable As DataTable
				camperAddDataTable = aDataSet.Camper.GetChanges(DataRowState.Added + DataRowState.Modified)
				Me.aCamperTableAdapter.Update(camperAddDataTable)
			End If

		Catch ex As Exception
			Throw ex
		End Try
	End Sub

	'Sql stuff pulled from Tutorial on DIC
	'dont know if any of this is helping at all

	''' <summary>
	''' Returns a BindingSource, which is used with, for example, a DataGridView control
	''' </summary>
	''' <param name="cmd">"pre-Loaded" command, ready to be executed</param>
	''' <returns>BindingSource</returns>
	''' <remarks>Use this function to ease populating controls that use a BindingSource</remarks>
	Public Shared Function GetBindingSource(ByVal cmd As SqlCommand) As BindingSource
		'declare our binding source
		Dim oBindingSource As New BindingSource()
		' Create a new data adapter based on the specified query.
		Dim daGet As New SqlDataAdapter(cmd)
		' Populate a new data table and bind it to the BindingSource.
		Dim dtGet As New DataTable()
		'set the timeout of the SqlCommandObject
		cmd.CommandTimeout = 240
		dtGet.Locale = System.Globalization.CultureInfo.InvariantCulture
		Try
			'fill the DataTable with the SqlDataAdapter
			daGet.Fill(dtGet)
		Catch ex As Exception
			'check for errors
			MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error receiving data")
			Return Nothing
		End Try
		'set the DataSource for the BindingSource to the DataTable
		oBindingSource.DataSource = dtGet
		'return the BindingSource to the calling method or control
		Return oBindingSource
	End Function
	''' <summary>
	''' Method for handling the ConnectionState of 
	''' the connection object passed to it
	''' </summary>
	''' <param name="conn">The SqlConnection Object</param>
	''' <remarks></remarks>
	Public Shared Sub HandleConnection(ByVal conn As SqlConnection)
		With conn
			'do a switch on the state of the connection
			Select Case .State
				Case ConnectionState.Open
					'the connection is open
					'close then re-open
					.Close()
					.Open()
					Exit Select
				Case ConnectionState.Closed
					'connection is open
					'open the connection
					.Open()
					Exit Select
				Case Else
					.Close()
					.Open()
					Exit Select
			End Select
		End With
	End Sub

	'procedures for passing variables from sql
	Public Shared Function InsertNewRecord(ByVal item1 As String, ByVal item2 As String, ByVal item3 As String) As Boolean
		'If not using the Express Edition uncomment the next line
		'Dim cnInsert As New SqlConnection(GetConnectionString("YourConnName"))
		'If using Express Edition uncomment the next line
		Dim cnInsert As New SqlConnection("F:\YouthCamp(CapStone FINAL)\YouthCamp(CapStone)\YouthCamp.mdf")
		Dim cmdInsert As New SqlCommand
		Dim sSQL As New String("")
		Dim iSqlStatus As Integer

		'Set the stored procedure we're going to execute
		sSQL = "YourProcName"

		'Inline sql needs to be structured like so
		'sSQL = "INSERT INTO YourTable(column1,column2,column3) VALUES('" & item1 & "','" & item2 & "','" & item3 & "')"

		'Clear any parameters
		cmdInsert.Parameters.Clear()
		Try
			'Set the SqlCommand Object Properties
			With cmdInsert
				'Tell it what to execute
				.CommandText = sSQL 'Your sql statement
				'Tell it its a stored procedure (if using inline sql uncomment this line
				'.CommandType = CommandType.StoredProcedure 'CommandType.Text for inline sql
				'If you arent using a stored procedure uncomment the next line
				'.CommandType = CommandType.StoredProcedure 'For inline sql
				'If you are indeed using a stored procedure
				'the next 3 lines pertain to you
				'Now add the parameters to our procedure
				'NOTE: Replace @value1.... with your parameter names in your stored procedure
				'and add all your parameters in this fashion
				.Parameters.AddWithValue("@value1", item1)
				.Parameters.AddWithValue("@value2", item2)
				.Parameters.AddWithValue("@value3", item3)
				'Set the connection of the object
				.Connection = cnInsert
			End With

			'Now take care of the connection
			HandleConnection(cnInsert)

			'Set the iSqlStatus to the ExecuteNonQuery 
			'status of the insert (0 = success, 1 = failed)
			iSqlStatus = cmdInsert.ExecuteNonQuery

			'Now check the status
			If Not iSqlStatus = 0 Then
				'DO your failed messaging here
				Return False
			Else
				'Do your success work here
				Return True
			End If
		Catch ex As Exception
			MsgBox("ex.Message,MsgBoxStyle.OkOnly", "Error")
		Finally
			'Now close the connection
			HandleConnection(cnInsert)
		End Try
	End Function


	Public Shared Function UpdateRecord(ByVal item1 As String, ByVal item2 As String, ByVal id As Integer) As Boolean
		'If not using the Express Edition uncomment the next line
		'Dim cnInsert As New SqlConnection(GetConnectionString("YourConnName"))
		'If using Express Edition uncomment the next line
		Dim cnInsert As New SqlConnection("F:\YouthCamp(CapStone FINAL)\YouthCamp(CapStone)\YouthCamp.mdf")
		Dim cmdUpdate As New SqlCommand
		Dim sSQL As New String("")
		Dim iSqlStatus As Integer

		'Set the stored procedure we're going to execute
		sSQL = "YourProcName"

		'Inline sql needs to be structured like so
		'sSQL = "UPDATE YourTable SET column1 = '" & item1 & "',column2 = '" & item2 & "' WHERE YourId = " & id

		'Clear any parameters
		cmdUpdate.Parameters.Clear()
		Try
			'Set the SqlCommand Object Properties
			With cmdUpdate
				'Tell it what to execute
				.CommandText = sSQL 'Your sql statement 
				'Tell it its a stored procedure (if using inline sql uncomment this line
				'.CommandType = CommandType.StoredProcedure 'CommandType.Text for inline sql
				'If you arent using a stored procedure uncomment the next line
				'.CommandType = CommandType.StoredProcedure 'For inline sql
				'If you are indeed using a stored procedure
				'the next 3 lines pertain to you
				'Now add the parameters to our procedure
				'NOTE: Replace @value1.... with your parameter names in your stored procedure
				'and add all your parameters in this fashion
				.Parameters.AddWithValue("@value1", item1)
				.Parameters.AddWithValue("@value2", item2)
				.Parameters.AddWithValue("@YourID", id)
				'Set the connection of the object
				.Connection = cnInsert
			End With

			'Now take care of the connection
			HandleConnection(cnInsert)

			'Set the iSqlStatus to the ExecuteNonQuery 
			'status of the insert (0 = success, 1 = failed)
			iSqlStatus = cmdUpdate.ExecuteNonQuery

			'Now check the status
			If Not iSqlStatus = 0 Then
				'DO your failed messaging here
				Return False
			Else
				'Do your success work here
				Return True
			End If
		Catch ex As Exception
			MsgBox("ex.Message,MsgBoxStyle.OkOnly", "Error")
		Finally
			'Now close the connection
			HandleConnection(cnInsert)
		End Try
	End Function

	Public Shared Function DeleteRecord(ByVal id As Integer) As Boolean
		'If not using the Express Edition uncomment the next line
		'Dim cnInsert As New SqlConnection(GetConnectionString("YourConnName"))
		'If using Express Edition uncomment the next line
		Dim cnInsert As New SqlConnection("F:\YouthCamp(CapStone FINAL)\YouthCamp(CapStone)\YouthCamp.mdf")
		Dim cmdDelete As New SqlCommand
		Dim sSQL As New String("")
		Dim iSqlStatus As Integer

		'Set the stored procedure we're going to execute
		sSQL = "YourProcName"

		'Inline sql needs to be structured like so
		'sSQL = "DELETE FROM YourTable WHERE YourID = " & id

		'Clear any parameters
		cmdDelete.Parameters.Clear()
		Try
			'Set the SqlCommand Object Properties
			With cmdDelete
				'Tell it what to execute
				.CommandText = sSQL 'Your sql statement if using inline sql
				'Tell it its a stored procedure (if using inline sql uncomment this line
				'.CommandType = CommandType.StoredProcedure 'CommandType.Text for inline sql
				'If you arent using a stored procedure uncomment the next line
				'.CommandType = CommandType.StoredProcedure 'For inline sql
				'If you are indeed using a stored procedure
				'the next 3 lines pertain to you
				'Now add the parameters to our procedure
				'NOTE: Replace @value1.... with your parameter names in your stored procedure
				'and add all your parameters in this fashion
				.Parameters.AddWithValue("@YourID", id)
				'Set the connection of the object
				.Connection = cnInsert
			End With

			'Now take care of the connection
			HandleConnection(cnInsert)

			'Set the iSqlStatus to the ExecuteNonQuery 
			'status of the insert (0 = success, 1 = failed)
			iSqlStatus = cmdDelete.ExecuteNonQuery

			'Now check the status
			If Not iSqlStatus = 0 Then
				'DO your failed messaging here
				Return False
			Else
				'Do your success work here
				Return True
			End If
		Catch ex As Exception
			MsgBox("ex.Message,MsgBoxStyle.OkOnly", "Error")
			Return False
		Finally
			'Now close the connection
			HandleConnection(cnInsert)
		End Try
	End Function



End Class


Thanks SO MUCH!! Anything you can do to help is really really appreciated! If I can do ANYTHING let me know ;)

This post has been edited by absynthe: 08 November 2008 - 03:43 PM

Was This Post Helpful? 0
  • +
  • -

#3 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Made alot of Progress but still isnt saving

Posted 09 November 2008 - 03:10 PM

My post is not letting me edit at all or I wouldn't reply to my own and bump.

Still needing help with Update and Saving..thanks!

Thank you so much Jason!! Now have the complete project zipped!

Attached File(s)


This post has been edited by absynthe: 09 November 2008 - 06:25 PM

Was This Post Helpful? 0
  • +
  • -

#4 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Made alot of Progress but still isnt saving

Posted 09 November 2008 - 04:54 PM

The ZIP file you attached contains only the .sln file, not the whole project.
Was This Post Helpful? 0
  • +
  • -

#5 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Made alot of Progress but still isnt saving

Posted 09 November 2008 - 05:47 PM

Remove the EXE file found in the bin/Debug folder then zip up the project and you can add it to your post.
Was This Post Helpful? 0
  • +
  • -

#6 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: Made alot of Progress but still isnt saving

Posted 09 November 2008 - 06:25 PM

FYI, you can't upload a file over 2MB.
Was This Post Helpful? 0
  • +
  • -

#7 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Made alot of Progress but still isnt saving

Posted 09 November 2008 - 06:26 PM

Finally got the file zipped! Thanks guys. Its here if you can help! :)
Was This Post Helpful? 0
  • +
  • -

#8 4x4pirate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 18-October 06

Re: Made alot of Progress but still isnt saving

Posted 09 November 2008 - 06:48 PM

View Postn8wxs, on 9 Nov, 2008 - 03:54 PM, said:

The ZIP file you attached contains only the .sln file, not the whole project.



I just figured out how to save my database.. if ur interested

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		Try
			Me.CustomerTBLTableAdapter.Insert(Me.txtFName.Text, Me.txtLName.Text, Me.txtAddress1.Text, txtAddress2.Text, txtCity.Text, txtSelectState.Text, txtPhone.Text, txtEmail.Text, txtZip.Text)
			Me.CustomerTBLTableAdapter.Fill(CustomersDatabaseDataSet.CustomerTBL)
		Catch ex As Exception
			MessageBox.Show(ex.Message, "Data input error")
		End Try


just edit with your variables... but you may be way past where I am anyway..

I created a datagrid as a form to verify that the data gets inserted after I submit while the program is running.

This post has been edited by 4x4pirate: 09 November 2008 - 06:49 PM

Was This Post Helpful? 0
  • +
  • -

#9 absynthe  Icon User is offline

  • DIC Tease
  • member icon

Reputation: 28
  • View blog
  • Posts: 2,807
  • Joined: 20-September 08

Re: Made alot of Progress but still isnt saving

Posted 09 November 2008 - 10:45 PM

Figured it out!! Ugh!! I was used to coding the method in Java but it turns out it was something I didnt do on the Data Designer with the "Update" Properties!! TWO DAMN DAYS ON IT...Ugh!! haha!! Thanks for the help though!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1