[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.mobile

Update Data in a remote Database

André Giesing

9/11/2003 1:06:00 PM

Hello Newsgroup!

I want to write a little WebService and an Application for a mobile Device
(Pocket PC 2002), which gets Data (a DataSet) from the WebService, which
reads the Data out of a SQL 2000 Server.
My little Application gets the DataSet and shows the Data in a DataGrid.
That works.

But now I want to edit the DataSet (not in the DataGrid, but over Textboxes
which are bound to the DataGrid-Collums) and send the edited DataSet back to
the WebService, which writes the Data back into the database.

I've tried a lot. At the end of this Mail you can the Source i have written.
But it does not work. The Database does not get the modifications of the
Data :-(

And this is my Problem. I hope someone can help me.


Here the Source-Code of my WebService:

[WebMethod]
public void SetKunden(DataSet dsKunde)
{
SqlConnection con;
SqlDataAdapter da;
SqlCommandBuilder cb;

string connectionString =
@"server=masp2;uid=sa;pwd=sa;database=MASPdaten;";

try
{
con = new SqlConnection(connectionString);

da = new SqlDataAdapter("SELECT Name, Strasse, Plz, Ort FROM Kunde", con);
da.ContinueUpdateOnError = true;
cb = new SqlCommandBuilder(da);

da.Update(dsKunde.Tables["Kunde"]);
}
catch(Exception ex)
{
}
}


And here the Source-Code out of my Client:

private void btnUpdate_Click(object sender, System.EventArgs e)
{
WebReference.Service ws = new WebReference.Service();

try
{
int rowIndex = dgKunden.CurrentRowIndex;

if(rowIndex >= 0 & rowIndex < m_dsDaten.Tables["Kunde"].Rows.Count)
{
DataRow tableRow = m_dsDaten.Tables["Kunde"].Rows[rowIndex];

if(txbName.Modified ||
txbStrasse.Modified ||
txbPlz.Modified ||
txbOrt.Modified)
{

string message = "Wollen Sie die Änderungen speichern?";
string caption = "Speichern";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
MessageBoxDefaultButton defaultbtn = MessageBoxDefaultButton.Button1;
MessageBoxIcon icon = MessageBoxIcon.Question;
DialogResult result;

result = MessageBox.Show(message, caption, buttons, icon, defaultbtn);

if(result == DialogResult.Yes)
{
tableRow["Name"] = txbName.Text;
tableRow["Strasse"] = txbStrasse.Text;
tableRow["Plz"] = txbPlz.Text;
tableRow["Ort"] = txbOrt.Text;

Refresh();
dgKunden.Refresh();

MessageBox.Show("Daten wurden gespeichert.");
}
if(result == DialogResult.No)
{
txbName.Text = name;
txbStrasse.Text = strasse;
txbPlz.Text = plz;
txbOrt.Text = ort;
Refresh();
}
}
}
txbName.ReadOnly = true;
txbStrasse.ReadOnly = true;
txbOrt.ReadOnly = true;
txbPlz.ReadOnly = true;

try
{
Cursor.Current=Cursors.WaitCursor;
DataSet changedDs = m_dsDaten.Clone();

foreach(DataRow row in m_dsDaten.Tables["Kunde"].Rows)
{
if(row.RowState!=System.Data.DataRowState.Unchanged)
{
changedDs.Tables["Kunde"].ImportRow(row);
}
if(changedDs.Tables["Kunde"].Rows.Count > 0)
{
ws.SetKunden(changedDs);
}
}
catch(Exception excp)
{
MessageBox.Show(excp.Message.ToString());
}
finally
{
Cursor.Current=Cursors.Default;
}
}
catch (Exception ex)
{
MessageBox.Show("Fehler in btnUpdate_Click: \n\n" + ex.ToString());
}
}