As title ... sigh **Correction ... TableAdapter**
I am new to DB-program, no friend know programming.
I have struggled on SQLConnection pointer for 1 day until i came this far ... *exhausted*
Really hope someone can give me advises and solutions to solve the "DataAdapter.Update(DataTable)"
The problem i having is update record to DB-File.
I am success in updating data into DataSet, but once program closed, Entry Gone.
I tried hard to use Adapter Update the Database Record from DataSet to DB-File (the code in bottom)
That code work for me, even program re-open the entry still exist, but it's not updating to DB-File too.
I also get error, and cant debug with Breakpoint.
I found DataAdapter method is the most easier way instead of using DataSet or BindingSource to Update the DB-File
Can help me out in Update using DataAdapter?
Thanks in advance .. .. ..
Me.customerCustomerTableTableAdapter.Update(Me.customerEBusiness_Management_DatabaseDataSet.customerTableDataTable)
Error :: 'customerTableDataTable' is a type in 'eBusiness_Management.eBusiness_Management_DatabaseDataSet' and cannot be used
~Full Coding inside Spoiler~
Private Sub customerSaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles customerSaveButton.Click
Dim mySQLConnection As SqlConnection
Dim mySQLCommand As SqlCommand
'Dim mySQLAdapter As SqlAdapter
Dim CommandPath As String
Dim DBLocation As String
DBLocation = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\eBusiness Management Database.mdf"
CommandPath = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & DBLocation & ";Integrated Security=True;User Instance=True"
mySQLConnection = New SqlClient.SqlConnection(CommandPath)
mySQLCommand = New SqlCommand("INSERT INTO customerTable(Cust_ID, Name, Address, City, State, Postal, Tel, Mobile) VALUES ('" & customerIDTextBox.Text & "','" & customerNameTextBox.Text & "','" & customerAddressTextBox.Text & "','" & customerCityTextBox.Text & "','" & customerStateTextBox.Text & "','" & customerPostalTextBox.Text & "','" & customerTelTextBox.Text & "','" & customerMobileTextBox.Text & "')", mySQLConnection)
Try
mySQLConnection.Open()
mySQLCommand.ExecuteNonQuery()
MessageBox.Show("Saved", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch myEx As Exception
MessageBox.Show("Coulnd't insert record: " + myEx.ToString())
Finally
'Update the Data to DataSet + Refresh customerDataGridView
mainForm.mainCustomerTableTableAdapter.Fill(mainForm.mainCustomer_EBusiness_Management_DatabaseDataSet.customerTable)
mainForm.customerDataGridView.Refresh()
Me.customerCustomerTableTableAdapter.Update(Me.customerEBusiness_Management_DatabaseDataSet.customerTableDataTable)
mySQLConnection.Close()
Me.Close()
End Try
End Sub
I am new to DB-program, no friend know programming.
I have struggled on SQLConnection pointer for 1 day until i came this far ... *exhausted*
Really hope someone can give me advises and solutions to solve the "DataAdapter.Update(DataTable)"
The problem i having is update record to DB-File.
I am success in updating data into DataSet, but once program closed, Entry Gone.
I tried hard to use Adapter Update the Database Record from DataSet to DB-File (the code in bottom)
That code work for me, even program re-open the entry still exist, but it's not updating to DB-File too.
I also get error, and cant debug with Breakpoint.
I found DataAdapter method is the most easier way instead of using DataSet or BindingSource to Update the DB-File
Can help me out in Update using DataAdapter?
Thanks in advance .. .. ..
Me.customerCustomerTableTableAdapter.Update(Me.customerEBusiness_Management_DatabaseDataSet.customerTableDataTable)
Error :: 'customerTableDataTable' is a type in 'eBusiness_Management.eBusiness_Management_DatabaseDataSet' and cannot be used
~Full Coding inside Spoiler~
Private Sub customerSaveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles customerSaveButton.Click
Dim mySQLConnection As SqlConnection
Dim mySQLCommand As SqlCommand
'Dim mySQLAdapter As SqlAdapter
Dim CommandPath As String
Dim DBLocation As String
DBLocation = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\eBusiness Management Database.mdf"
CommandPath = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & DBLocation & ";Integrated Security=True;User Instance=True"
mySQLConnection = New SqlClient.SqlConnection(CommandPath)
mySQLCommand = New SqlCommand("INSERT INTO customerTable(Cust_ID, Name, Address, City, State, Postal, Tel, Mobile) VALUES ('" & customerIDTextBox.Text & "','" & customerNameTextBox.Text & "','" & customerAddressTextBox.Text & "','" & customerCityTextBox.Text & "','" & customerStateTextBox.Text & "','" & customerPostalTextBox.Text & "','" & customerTelTextBox.Text & "','" & customerMobileTextBox.Text & "')", mySQLConnection)
Try
mySQLConnection.Open()
mySQLCommand.ExecuteNonQuery()
MessageBox.Show("Saved", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch myEx As Exception
MessageBox.Show("Coulnd't insert record: " + myEx.ToString())
Finally
'Update the Data to DataSet + Refresh customerDataGridView
mainForm.mainCustomerTableTableAdapter.Fill(mainForm.mainCustomer_EBusiness_Management_DatabaseDataSet.customerTable)
mainForm.customerDataGridView.Refresh()
Me.customerCustomerTableTableAdapter.Update(Me.customerEBusiness_Management_DatabaseDataSet.customerTableDataTable)
mySQLConnection.Close()
Me.Close()
End Try
End Sub
Last edited: