To add a new row to a strongly typed dataset:
Dim ds As New NorthwindDataSet()
Dim tblCustomers As NorthwindDataSet.CustomersDataTable _
= ds.Customers
Dim rowCustomer As NorthwindDataSet.CustomersRow
rowCustomer.CustomerID = "NEWCO"
rowCustomer.CompanyName = "New Company"
tblCustomers.AddCustomersRow(rowCustomer)
'another way
tblCustomers.AddCustomersRow("NEWC2", "Another Co")
To remove update capability, you can change this on the
BindingSource:
MtrUnitBindingSource.AllowEdit = False
MtrUnitBindingSource.AllowNew = False
MtrUnitBindingSource.AllowRemove = False
To reset the add/change/delete ability back to whatever is
supported by the underlying data source:
MtrUnitBindingSource.ResetAllowNew
MtrUnitBindingSource.AllowEdit = True
MtrUnitBindingSource.AllowRemove = True
HTH,
Robin S.
-----------------------------------------------
[quoted text, click to view] "Benson" <bensonwyl@yahoo.com.hk> wrote in message
news:%23z6%23ZZSQHHA.1200@TK2MSFTNGP02.phx.gbl...
>I create a typed dataset by drag'n'drop in VS2005 (VB). I can use
>FillBy or GetDataBy methods to retrieve the record. The code is as
>follows:
>
> dataTable = tableAdapter.GetDataByCode(KeyFieldValue)
> MtrUnitBindingSource.DataSource = dataTable
> 'user edits the record
> 'press ok button to save
> MtrUnitBindingSource.EndEdit()
> tableAdapter.Update(dataTable)
> ==> it works perfectly in find/edit/update mode.
> Question:
> 1. I find difficulty in New/Insert mode. How to add a new row and do
> the insert to the database?
> 2. If in the view mode (only user views the record), how to set
> datatable to readonly?
>
> Benson
> VB2005
>