Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Mobile > Update Data in a remote Database

Reply
Thread Tools

Update Data in a remote Database

 
 
André Giesing
Guest
Posts: n/a
 
      09-11-2003
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.Unchange d)
{
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());
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Remote Assistance fails to connect, remote remote host name could not be resolved Peter Sale Wireless Networking 1 12-11-2004 09:09 PM
[BUG?] Update database using stored procedure and OleDbDataAdapter.Update joun ASP .Net 9 11-30-2004 04:57 AM
Update Data in a remote Database André Giesing ASP .Net Web Services 3 09-11-2003 09:43 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57