Update Data in a remote Database

Discussion in 'ASP .Net Mobile' started by André Giesing, Sep 11, 2003.

  1. 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());
    }
    }
     
    André Giesing, Sep 11, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. joun
    Replies:
    9
    Views:
    2,242
    W.G. Ryan eMVP
    Nov 30, 2004
  2. joun
    Replies:
    5
    Views:
    2,670
  3. GS
    Replies:
    1
    Views:
    2,685
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Jan 19, 2006
  4. Alina Ghergu
    Replies:
    3
    Views:
    500
    Alina Ghergu
    Sep 6, 2006
  5. André Giesing

    Update Data in a remote Database

    André Giesing, Sep 11, 2003, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    166
    Severin
    Sep 11, 2003
Loading...

Share This Page