Dataset X DataBase

  • Thread starter Thread starter Rodrigo
  • Start date Start date
R

Rodrigo

Dears,

I have had problems to save the changes made on a form to the database. When
I call the code bellow the changes are made only at the dataset, but when I
refresh the form the data keeps unchanged.
I need this help to continue with my project. If can help I can send the
full source.

private void tbar_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
try
{
switch(tbar.Buttons.IndexOf(e.Button))
{
case 0:
try
{
int record = BindingContext[dsCliente.Tables["tbCLIENTE"]].Position;
daCliente.Update(dsCliente, "tbCLIENTE");
dsCliente.Tables["tbCLIENTE"].Rows[record].EndEdit();
dsCliente.AcceptChanges();
break;
}
catch
{
}
case 1:
//MessageBox.Show("Copiar");
break;
case 2:
//MessageBox.Show("Apagar");
break;
}
}
catch
{
MessageBox.Show("Erro ao Salvar");
}
}
}
 
You need to pass your DataSet back to the database using a DataAdapter.
Configure its InsertCommand, UpdateCommand and DeleteCommand as needed and
then call its Update method passing the DataSet containing the changes.

Hope this helps
 
Dear Jose,

I've made this already at line below.

daCliente.Update(dsCliente, "tbCLIENTE");

The daCliente dataadapter updates the dsCliente dataset as you can see.

The upcadatecommand setup is:

daCliente = new SqlCeDataAdapter(sqlCliente, cnDB);

daCliente.UpdateCommand = new SqlCeCommand(usqlCliente, cnDB);

daCliente.UpdateCommand.Parameters.Add(new SqlCeParameter("@cFANTASIA",
SqlDbType.NVarChar, 255, "cFANTASIA"));

daCliente.UpdateCommand.Parameters.Add(new SqlCeParameter("@cTELEFONE",
SqlDbType.NVarChar, 30, "cTELEFONE"));

daCliente.UpdateCommand.Parameters.Add(new SqlCeParameter("@cSITE",
SqlDbType.NVarChar, 255, "cSITE"));

daCliente.UpdateCommand.Parameters.Add(new SqlCeParameter("@nCLIENTE",
SqlDbType.Float, 255, "nCLIENTE"));

If you want to see the full code I can send to you.

Thanks

Rodrigo


Jose Luis Balsera said:
You need to pass your DataSet back to the database using a DataAdapter.
Configure its InsertCommand, UpdateCommand and DeleteCommand as needed and
then call its Update method passing the DataSet containing the changes.

Hope this helps

Rodrigo said:
Dears,

I have had problems to save the changes made on a form to the database. When
I call the code bellow the changes are made only at the dataset, but
when
I
refresh the form the data keeps unchanged.
I need this help to continue with my project. If can help I can send the
full source.

private void tbar_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
try
{
switch(tbar.Buttons.IndexOf(e.Button))
{
case 0:
try
{
int record = BindingContext[dsCliente.Tables["tbCLIENTE"]].Position;
daCliente.Update(dsCliente, "tbCLIENTE");
dsCliente.Tables["tbCLIENTE"].Rows[record].EndEdit();
dsCliente.AcceptChanges();
break;
}
catch
{
}
case 1:
//MessageBox.Show("Copiar");
break;
case 2:
//MessageBox.Show("Apagar");
break;
}
}
catch
{
MessageBox.Show("Erro ao Salvar");
}
}
}
 
Hi Rodrigo,

I'm sorry, I did't see the call to Update .-)
Let's see if I can still help here,... I think the problem is that Update must be called after EndEdit

--
Jose Luis Balsera
www.raona.com

Remove "collaboration" from my e-mail address to answer privately



Rodrigo said:
Dear Jose,

I've made this already at line below.

daCliente.Update(dsCliente, "tbCLIENTE");

The daCliente dataadapter updates the dsCliente dataset as you can see.

The upcadatecommand setup is:

daCliente = new SqlCeDataAdapter(sqlCliente, cnDB);

daCliente.UpdateCommand = new SqlCeCommand(usqlCliente, cnDB);

daCliente.UpdateCommand.Parameters.Add(new SqlCeParameter("@cFANTASIA",
SqlDbType.NVarChar, 255, "cFANTASIA"));

daCliente.UpdateCommand.Parameters.Add(new SqlCeParameter("@cTELEFONE",
SqlDbType.NVarChar, 30, "cTELEFONE"));

daCliente.UpdateCommand.Parameters.Add(new SqlCeParameter("@cSITE",
SqlDbType.NVarChar, 255, "cSITE"));

daCliente.UpdateCommand.Parameters.Add(new SqlCeParameter("@nCLIENTE",
SqlDbType.Float, 255, "nCLIENTE"));

If you want to see the full code I can send to you.

Thanks

Rodrigo


Jose Luis Balsera said:
You need to pass your DataSet back to the database using a DataAdapter.
Configure its InsertCommand, UpdateCommand and DeleteCommand as needed and
then call its Update method passing the DataSet containing the changes.

Hope this helps

Rodrigo said:
Dears,

I have had problems to save the changes made on a form to the database. When
I call the code bellow the changes are made only at the dataset, but
when
I
refresh the form the data keeps unchanged.
I need this help to continue with my project. If can help I can send the
full source.

private void tbar_ButtonClick(object sender,
System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
try
{
switch(tbar.Buttons.IndexOf(e.Button))
{
case 0:
try
{
int record = BindingContext[dsCliente.Tables["tbCLIENTE"]].Position;
daCliente.Update(dsCliente, "tbCLIENTE");
dsCliente.Tables["tbCLIENTE"].Rows[record].EndEdit();
dsCliente.AcceptChanges();
break;
}
catch
{
}
case 1:
//MessageBox.Show("Copiar");
break;
case 2:
//MessageBox.Show("Apagar");
break;
}
}
catch
{
MessageBox.Show("Erro ao Salvar");
}
}
}
 
Back
Top