SQL Server Express *VB.NET2005, "Cant Update using DataAdapter"

glen_cct

New member
Joined
Oct 16, 2007
Messages
2
Programming Experience
Beginner
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
 
Last edited:
arr i have done saving entry into the DB-File
I found the reason, that is not coding problem, but the DB-FILE (MDF or SQL Express File) will overwriting the File which contain data.

this page tell the problem...
http://blogs.msdn.com/smartclientdata/arch.../26/456886.aspx

To people who using SQL Server 2005 Express *.MDF file
May met this problem.

*thanks for the people looking into my problem*
 
This question has come up lots on the forum, doing a search for "updates not showing" or similar would of shown all the threads!

They always end up with the same answer, that which I have got linked to in my signature - http://vbdotnetforums.com/showthread.php?p=54914
 
Back
Top