Hi,
I use this code to save data from a win form to a database
Edit:
The connection string.
However, while it works without fault in the AddCust form in the AddProd the same code saving the data half the time. Also, Sometimes if I reload the application after using form AddProd to add data to the database (verifying by checking the data in the Server Explorer) the data disappears. What could cause this?
Thanks,
Nightwalker
I use this code to save data from a win form to a database
vb.net Code:
Public Class frmAddCust Private alibraryDS As New LibraryDataSet Private aCustomersTA As LibraryDataSetTableAdapters.CustomersTableAdapter Private customersBS As New BindingSource Private Sub frmAddCust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try 'Set up the dataset aCustomersTA = New LibraryDataSetTableAdapters.CustomersTableAdapter aCustomersTA.Fill(alibraryDS.Customers) 'Set up binding source customersBS.DataSource = alibraryDS customersBS.DataMember = "Customers" 'Bind the controls txtID.DataBindings.Add("text", customersBS, "CustomerID") txtFName.DataBindings.Add("text", customersBS, "FirstName") txtLName.DataBindings.Add("text", customersBS, "LastName") tpDate.DataBindings.Add("text", customersBS, "DateJoined") label1.Text = "CustomerID" Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Private Sub cmdRegister_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRegister.Click If cmdRegister.Text = "Register" Then customersBS.EndEdit() customersBS.AddNew() txtID.Focus() cmdRegister.Text = "Save" Else Try 'Save Button clicked customersBS.EndEdit() aCustomersTA.Update(alibraryDS.Customers) cmdRegister.Text = "Register" MessageBox.Show("Record Saved", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As Exception 'Catch deplicate record and constraint violations MessageBox.Show(ex.Message) End Try End If End Sub End Class
Edit:
The connection string.
Code:
<connectionStrings>
<add name="WindowsApplication2.My.MySettings.LibraryConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Library.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>Thanks,
Nightwalker





