First I created 2 DataSources:
1) MBLDataset has 1 datatable MBList that retrieves only 3 columns from the
"Mailboxes" table in the SQL database. I left the datable to be in
DataGridview
2) MBDataSet has 1 datatable MBDetails that retrieves all the columns from
the same Mailboxes table. The databale was changed to show Details on the
form.
For the MBDataSet I modified the Fill command to take a paramter:
Fill(@BoxNumber) and modified the Select staetment to add: "WHERE
(BoxNumber = @BoxNumber)". That was done via the TableAdapter Configuration
Wizard.
Second I dragged on to the Form1 the MBList from the DataSources window and
that worked fine. All the recoords are retrieved from the table and it
display BoxNumber, LastName, FirstName in the data grid and it created the
navigation bar.
Third I dragged on the Form1 the MBDetails from the DataSources window and
it generated all the fields for detail view and allowed them to be edited. I
want to only retrieve the specific record that is selected in the MBList
dataGrid to be retrieved and shown in the Details fields. That is why I
changed the Fill command to use a Where clause. That part is working.
Finally I created a Button1 to Save the edits in the details record as
below. This is the code that gets the error message as you can see in the
Catch() statement.
private void button1_Click(object sender, EventArgs e)
{
try
{
this.mBDetailsBindingSource.EndEdit();
//this.mBDetailsTableAdapter.Update(this.mBDataSet.MBDetails);
this.mBDetailsTableAdapter.Update(this.mBDataSet.MBDetails.Rows[0]);
}
catch (System.Exception ex)
{
MessageBox.Show("Update failed. \nReason: " +
ex.Message.ToString(),"mbUpdate");
}
}
Also for the Form_Load and Row_enter functions is listed below.
I set the following
private void MailBoxForm_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'mailboxtest.Mailboxes' table. You can move, or remove it, as needed.
this.mailboxesTableAdapter.Fill(this.mailboxtest.Mailboxes);
// TODO: This line of code loads data into the
'mBLDataSet.MBList' table. You can move, or remove it, as needed.
this.mbDefaultsTableAdapter.Fill(this.mbDefaultsDataSet.MBDefaults);
this.mBListTableAdapter.Fill(this.mBLDataSet.MBList);
this.mBDetailsTableAdapter.Fill(this.mBDataSet.MBDetails,
this.mBListDataGridView.CurrentRow.Cells[0].Value.ToString());
this.mBListDataGridView.RowEnter += new
System.Windows.Forms.DataGridViewCellEventHandler(this.mBListDataGridView_RowEnter);
this.mBListDataGridView.RowsAdded += new
System.Windows.Forms.DataGridViewRowsAddedEventHandler(this.mBListDataGridView_RowsAdded);
}
private void mBListDataGridView_RowEnter(object sender, EventArgs e)
{
// retrieve the selected record's details.
int intFill =
this.mBDetailsTableAdapter.Fill(this.mBDataSet.MBDetails,
this.mBListDataGridView.SelectedRows[0].Cells[0].Value.ToString());
if (intFill == 0) // no existing record must be new so get
default values.
{
// get default values from NewAccountDefault Table.
this.boxNumberTextBox.Text =
mBListDataGridView.SelectedRows[0].Cells[0].Value.ToString();
this.lastNameTextBox.Text =
mBListDataGridView.SelectedRows[0].Cells[1].Value.ToString();
this.firstNameTextBox.Text =
mBListDataGridView.SelectedRows[0].Cells[2].Value.ToString();
this.maxNewMessagesTextBox.Text =
this.mbDefaultsDataSet.MBDefaults.Rows[0].ItemArray.GetValue(1).ToString();
this.maxSavedMessagesTextBox.Text =
this.mbDefaultsDataSet.MBDefaults.Rows[0].ItemArray.GetValue(2).ToString();
this.maxMessageLengthTextBox.Text =
this.mbDefaultsDataSet.MBDefaults.Rows[0].ItemArray.GetValue(3).ToString();
this.maxMessageAgeTextBox.Text =
this.mbDefaultsDataSet.MBDefaults.Rows[0].ItemArray.GetValue(4).ToString();
this.flagsTextBox.Text =
this.mbDefaultsDataSet.MBDefaults.Rows[0].ItemArray.GetValue(5).ToString();
}
}
The MBDetails.Update() command was also generated by the TableAdapter
Configuration Wizard.
I am guessing it has to do with the fact I added the Where clause in the
Fill()?
Does this give you any clue as to what is going wrong?
Thanks for your help.
--
Thanks
Morris
"Wen Yuan Wang [MSFT]" said:
Hello Morris,
Sorry for delay, due to weekend.
To create a method for partial tableAdapter class, you can follow the steps
as below. Then you can expose the internal Adapter in that method, and
check each parameter value in its updating event. I believe you may find
some of them are empty. This is the reason why tableAdapter throw an error
while updating. But, I'm afraid to say this doesn't help on narrow down the
issue. This method doesn't tell us why the parameter isn't copied from
dataset. Each parameter should be filled in update () method automatically.
According to your description, you have made no code changes to any of the
Designer generated code and have only added event handlers to the Form.cs
file to issue the update. Could you please provide more detailed
information about how did you add the Typed DataSet and add event to issue
the update? I will try to reproduce the issue on my side and perform
further research on it.
http://msdn.microsoft.com/en-us/library/ms233697(VS.80).aspx
[How to: Extend the Functionality of a TableAdapter ]
==============================================================
namespace ConsoleApplication16.DataSet1TableAdapters
{
public partial class table1TableAdapter
{
public System.Data.SqlClient.SqlDataAdapter getDataAdatper()
{
return this._adapter;
}
}
}
In your application.cs file:
DataSet1TableAdapters.table1TableAdapter tta = new
ConsoleApplication16.DataSet1TableAdapters.table1TableAdapter();
tta.getDataAdatper().RowUpdating += new
System.Data.SqlClient.SqlRowUpdatingEventHandler(Program_RowUpdating);
....
==============================================================
Have a great day,
Best regards,
Wen Yuan
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.