Please Urgent - Update Data Source Problem ???

G

Guest

I'm facing problem to update the data source after I make changes to the data table. I try to call DataAdapter.Update() to transmit the changes cached in DataSet to the database, but it didn't work ???

Can any one help me ??? Bekow are the full program can anyone please kind to check for me, I've been try to solve this problems more than 5 days

Thankssssssss...very.....very muc

using System
using System.Drawing
using System.Collections
using System.ComponentModel
using System.Windows.Forms
using System.IO
using System.Data
using System.Text
using System.Data.SqlServerCe
using System.Data.Common

namespace UpdateD

public class Form1 : System.Windows.Forms.For

private System.Windows.Forms.Button btnRetrieve
private System.Windows.Forms.Button btnUpdate
private System.Windows.Forms.TextBox txtTask
private System.Windows.Forms.TextBox txtTime
private System.Windows.Forms.TextBox txtDate
private System.Windows.Forms.MainMenu mainMenu1
private System.Windows.Forms.Button btnShow
private System.Windows.Forms.DataGrid g1
SqlCeCommand cmdSelect = new SqlCeCommand()
SqlCeCommand cmdUpdate = new SqlCeCommand()
SqlCeCommand cmdInsert = new SqlCeCommand()
SqlCeCommand cmdDelete = new SqlCeCommand()
SqlCeParameter prm = new SqlCeParameter()
SqlCeConnection cnn = new SqlCeConnection(cn)
SqlCeDataAdapter da = new SqlCeDataAdapter()
static string cn = @"Data Source = \My Documents\MSFA.sdf"
string str = "Schedule Data\nDate: {0}\nTime: {1}\nTask: {2}"
DataTable dt;
DataSet ds;

public Form1(

InitializeComponent()


protected override void Dispose( bool disposing

base.Dispose( disposing )

#region Windows Form Designer generated cod
/// <summary
/// Required method for Designer support - do not modif
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(

this.mainMenu1 = new System.Windows.Forms.MainMenu()
this.btnRetrieve = new System.Windows.Forms.Button()
this.btnUpdate = new System.Windows.Forms.Button()
this.txtTask = new System.Windows.Forms.TextBox()
this.txtTime = new System.Windows.Forms.TextBox()
this.txtDate = new System.Windows.Forms.TextBox()
this.g1 = new System.Windows.Forms.DataGrid()
this.btnShow = new System.Windows.Forms.Button()
//
// btnRetriev
//
this.btnRetrieve.Location = new System.Drawing.Point(30, 248)
this.btnRetrieve.Text = "select"
this.btnRetrieve.Click += new System.EventHandler(this.btnRetrieve_Click)
//
// btnUpdat
//
this.btnUpdate.Location = new System.Drawing.Point(126, 248)
this.btnUpdate.Text = "Update"
this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click)
//
// txtTas
//
this.txtTask.Location = new System.Drawing.Point(6, 184)
this.txtTask.Size = new System.Drawing.Size(224, 22)
this.txtTask.Text = ""
//
// txtTim
//
this.txtTime.Location = new System.Drawing.Point(134, 152)
this.txtTime.Text = ""
//
// txtDat
//
this.txtDate.Location = new System.Drawing.Point(6, 152)
this.txtDate.Text = ""
//
// g
//
this.g1.Size = new System.Drawing.Size(240, 112)
this.g1.Text = "g1"
//
// btnSho
//
this.btnShow.Location = new System.Drawing.Point(32, 216)
this.btnShow.Text = "show"
this.btnShow.Click += new System.EventHandler(this.btnShow_Click)
//
// Form
//
this.Controls.Add(this.btnShow)
this.Controls.Add(this.g1)
this.Controls.Add(this.btnRetrieve)
this.Controls.Add(this.btnUpdate)
this.Controls.Add(this.txtTask)
this.Controls.Add(this.txtTime)
this.Controls.Add(this.txtDate)
this.Menu = this.mainMenu1
this.Text = "Form1"
this.Load += new System.EventHandler(this.Form1_Load)


#endregio

static void Main()

Application.Run(new Form1())


private void btnUpdate_Click(object sender, System.EventArgs e

tr

cmdSelect = cnn.CreateCommand()
cmdSelect.CommandText = "SELECT * FROM Schedule"
da.SelectCommand = cmdSelect;

cmdUpdate = cnn.CreateCommand();
cmdUpdate.CommandText = "UPDATE Schedule" +
"SET DATE = ?,Time = ?, Task = ? " +
"WHERE Date = ? AND Time = ? AND Task = ? ";
SqlCeParameterCollection pc = cmdUpdate.Parameters;
pc.Add("Date_New", SqlDbType.NVarChar,15, "Date");
pc.Add("Time_New", SqlDbType.NVarChar,15, "Time");
pc.Add("Task_New", SqlDbType.NVarChar,15, "Task");

prm = cmdUpdate.Parameters.Add("Date_Orig", SqlDbType.NVarChar, 15, "Date");
prm = cmdUpdate.Parameters.Add("Time_Orig", SqlDbType.NVarChar, 15, "Time");
prm = cmdUpdate.Parameters.Add("Task_Orig", SqlDbType.NVarChar, 15, "Task");
prm.SourceVersion = DataRowVersion.Original;
da.UpdateCommand = cmdUpdate;

cmdDelete = cnn.CreateCommand();
cmdDelete.CommandText = "DELETE FROM Schedule WHERE Date = ? AND Time = ? AND Task = ? ";
prm = cmdDelete.Parameters.Add("Date", SqlDbType.NVarChar, 15, "Date");
prm = cmdDelete.Parameters.Add("Time", SqlDbType.NVarChar, 15, "Time");
prm = cmdDelete.Parameters.Add("Task", SqlDbType.NVarChar, 15, "Task");
prm.SourceVersion = DataRowVersion.Original;
da.DeleteCommand = cmdDelete;

cmdInsert = cnn.CreateCommand();
cmdInsert.CommandText = "INSERT INTO Schedule(Date, Time, Task) " +
"VALUES(?, ?, ?)";
prm = cmdInsert.Parameters.Add("Date", SqlDbType.NVarChar, 15, "Date");
prm = cmdInsert.Parameters.Add("Time", SqlDbType.NVarChar, 15, "Time");
prm = cmdInsert.Parameters.Add("Task", SqlDbType.NVarChar, 15, "Task");
da.InsertCommand = cmdInsert;
}

catch (SqlCeException)
{
}
}


private void btnShow_Click(object sender, System.EventArgs e)
{
try
{
da.Update(ds, "Schedule");
}

catch (SqlCeException){}

}

private void Form1_Load(object sender, System.EventArgs e)
{
SqlCeConnection conn = null;
try
{
if (! File.Exists (@"\My Documents\MSFA.sdf"))
{
SqlCeEngine engine = new SqlCeEngine (
@"Data Source = \My Documents\MSFA.sdf");
engine.CreateDatabase();
}

conn = new SqlCeConnection (@"Data Source = \My Documents\MSFA.sdf");
conn.Open();

SqlCeCommand cmd = conn.CreateCommand();

cmd.CommandText =
"CREATE TABLE Schedule (Date NVARCHAR(15), Time NVARCHAR(15), Task NVARCHAR(15))";
cmd.ExecuteNonQuery();

cmd.CommandText =
"INSERT INTO Schedule (Date, Time, Task)" +
"VALUES ('3/18/2004', '08.00 am', 'Do BCP')";
cmd.ExecuteNonQuery();

cmd.CommandText =
"INSERT INTO Schedule (Date, Time, Task)" +
"VALUES ('3/18/2004', '08.30 am', 'Sleep')";
cmd.ExecuteNonQuery();

cmd.CommandText =
"INSERT INTO Schedule (Date, Time, Task)" +
"VALUES ('3/19/2004', '09.00 am', 'Do')";
cmd.ExecuteNonQuery();

}

catch (SqlCeException){}


finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}

string cn = @"Data Source = \My Documents\MSFA.sdf";

using(SqlCeConnection cn1 = new SqlCeConnection(cn))
{
cn1.Open();
string select = "SELECT * FROM Schedule";
SqlCeDataAdapter da = new SqlCeDataAdapter();

da.MissingMappingAction = MissingMappingAction.Passthrough;
da.MissingSchemaAction = MissingSchemaAction.Add;
da.SelectCommand = new SqlCeCommand(select, cn1);

ds = new DataSet();
da.Fill(ds, "Schedule");
dt = ds.Tables["Schedule"];
g1.DataSource = dt;
txtDate.DataBindings.Clear();
txtDate.DataBindings.Add("Text", dt, "Date");
txtTime.DataBindings.Clear();
txtTime.DataBindings.Add("Text", dt, "Time");
txtTask.DataBindings.Clear();
txtTask.DataBindings.Add("Text", dt, "Task");
}

}


private void btnRetrieve_Click(object sender, System.EventArgs e)
{
SqlCeConnection conn = null;
SqlCeCommand comm = null;
using( conn = new SqlCeConnection(cn))
{
conn.Open();
string q4 = "SELECT * FROM Schedule";
SqlCeDataReader dr = null;
try
{
comm = new SqlCeCommand(q4, conn);
comm.CommandType = CommandType.Text;
dr = comm.ExecuteReader(CommandBehavior.Default);

while(dr.Read())
{
MessageBox.Show(string.Format(str, dr.GetString(0),dr.GetString(1), dr.GetString(2)));
}
}

catch (SqlCeException) {}

finally
{
if (comm != null)
comm.Dispose();

if (dr != null)
dr.Close();
}
}

}
}
}
 
W

William Ryan eMVP

Lianna:

I don't see where you are changing the values.....Right before you call
update, use Debug.Assert(ds.HasChanges) and see if the assertion fails. If
it doesn't, then the likely problem is the update logic. Your try catch
blocks also just eat the exception and may be hiding something. Use
Debug.Assert(false, ex.ToString()); or MessageBox.Show(ex.ToString()); and
see if you're raising an exception.

Remember that if you have CE open with Query analyser or something else, you
may not be getting an open connection and your exc handlers may be
disquising it.

First, verify that your dataset haschanges, b/c if not, the rest is moot.
Next, verify that you aren't throwing any exceptions on update.

HTH,

Bill
Lianna said:
I'm facing problem to update the data source after I make changes to the
data table. I try to call DataAdapter.Update() to transmit the changes
cached in DataSet to the database, but it didn't work ???
Can any one help me ??? Bekow are the full program can anyone please kind
to check for me, I've been try to solve this problems more than 5 days
Thankssssssss...very.....very much

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Data;
using System.Text;
using System.Data.SqlServerCe;
using System.Data.Common;

namespace UpdateDB
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnRetrieve;
private System.Windows.Forms.Button btnUpdate;
private System.Windows.Forms.TextBox txtTask;
private System.Windows.Forms.TextBox txtTime;
private System.Windows.Forms.TextBox txtDate;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.Button btnShow;
private System.Windows.Forms.DataGrid g1;
SqlCeCommand cmdSelect = new SqlCeCommand();
SqlCeCommand cmdUpdate = new SqlCeCommand();
SqlCeCommand cmdInsert = new SqlCeCommand();
SqlCeCommand cmdDelete = new SqlCeCommand();
SqlCeParameter prm = new SqlCeParameter();
SqlCeConnection cnn = new SqlCeConnection(cn);
SqlCeDataAdapter da = new SqlCeDataAdapter();
static string cn = @"Data Source = \My Documents\MSFA.sdf";
string str = "Schedule Data\nDate: {0}\nTime: {1}\nTask: {2}";
DataTable dt;
DataSet ds;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.btnRetrieve = new System.Windows.Forms.Button();
this.btnUpdate = new System.Windows.Forms.Button();
this.txtTask = new System.Windows.Forms.TextBox();
this.txtTime = new System.Windows.Forms.TextBox();
this.txtDate = new System.Windows.Forms.TextBox();
this.g1 = new System.Windows.Forms.DataGrid();
this.btnShow = new System.Windows.Forms.Button();
//
// btnRetrieve
//
this.btnRetrieve.Location = new System.Drawing.Point(30, 248);
this.btnRetrieve.Text = "select";
this.btnRetrieve.Click += new System.EventHandler(this.btnRetrieve_Click);
//
// btnUpdate
//
this.btnUpdate.Location = new System.Drawing.Point(126, 248);
this.btnUpdate.Text = "Update";
this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
//
// txtTask
//
this.txtTask.Location = new System.Drawing.Point(6, 184);
this.txtTask.Size = new System.Drawing.Size(224, 22);
this.txtTask.Text = "";
//
// txtTime
//
this.txtTime.Location = new System.Drawing.Point(134, 152);
this.txtTime.Text = "";
//
// txtDate
//
this.txtDate.Location = new System.Drawing.Point(6, 152);
this.txtDate.Text = "";
//
// g1
//
this.g1.Size = new System.Drawing.Size(240, 112);
this.g1.Text = "g1";
//
// btnShow
//
this.btnShow.Location = new System.Drawing.Point(32, 216);
this.btnShow.Text = "show";
this.btnShow.Click += new System.EventHandler(this.btnShow_Click);
//
// Form1
//
this.Controls.Add(this.btnShow);
this.Controls.Add(this.g1);
this.Controls.Add(this.btnRetrieve);
this.Controls.Add(this.btnUpdate);
this.Controls.Add(this.txtTask);
this.Controls.Add(this.txtTime);
this.Controls.Add(this.txtDate);
this.Menu = this.mainMenu1;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

static void Main()
{
Application.Run(new Form1());
}

private void btnUpdate_Click(object sender, System.EventArgs e)
{
try
{
cmdSelect = cnn.CreateCommand();
cmdSelect.CommandText = "SELECT * FROM Schedule";
da.SelectCommand = cmdSelect;

cmdUpdate = cnn.CreateCommand();
cmdUpdate.CommandText = "UPDATE Schedule" +
"SET DATE = ?,Time = ?, Task = ? " +
"WHERE Date = ? AND Time = ? AND Task = ? ";
SqlCeParameterCollection pc = cmdUpdate.Parameters;
pc.Add("Date_New", SqlDbType.NVarChar,15, "Date");
pc.Add("Time_New", SqlDbType.NVarChar,15, "Time");
pc.Add("Task_New", SqlDbType.NVarChar,15, "Task");

prm = cmdUpdate.Parameters.Add("Date_Orig", SqlDbType.NVarChar, 15, "Date");
prm = cmdUpdate.Parameters.Add("Time_Orig", SqlDbType.NVarChar, 15, "Time");
prm = cmdUpdate.Parameters.Add("Task_Orig", SqlDbType.NVarChar, 15, "Task");
prm.SourceVersion = DataRowVersion.Original;
da.UpdateCommand = cmdUpdate;

cmdDelete = cnn.CreateCommand();
cmdDelete.CommandText = "DELETE FROM Schedule WHERE Date = ? AND Time = ? AND Task = ? ";
prm = cmdDelete.Parameters.Add("Date", SqlDbType.NVarChar, 15, "Date");
prm = cmdDelete.Parameters.Add("Time", SqlDbType.NVarChar, 15, "Time");
prm = cmdDelete.Parameters.Add("Task", SqlDbType.NVarChar, 15, "Task");
prm.SourceVersion = DataRowVersion.Original;
da.DeleteCommand = cmdDelete;

cmdInsert = cnn.CreateCommand();
cmdInsert.CommandText = "INSERT INTO Schedule(Date, Time, Task) " +
"VALUES(?, ?, ?)";
prm = cmdInsert.Parameters.Add("Date", SqlDbType.NVarChar, 15, "Date");
prm = cmdInsert.Parameters.Add("Time", SqlDbType.NVarChar, 15, "Time");
prm = cmdInsert.Parameters.Add("Task", SqlDbType.NVarChar, 15, "Task");
da.InsertCommand = cmdInsert;
}

catch (SqlCeException)
{
}
}


private void btnShow_Click(object sender, System.EventArgs e)
{
try
{
da.Update(ds, "Schedule");
}

catch (SqlCeException){}

}

private void Form1_Load(object sender, System.EventArgs e)
{
SqlCeConnection conn = null;
try
{
if (! File.Exists (@"\My Documents\MSFA.sdf"))
{
SqlCeEngine engine = new SqlCeEngine (
@"Data Source = \My Documents\MSFA.sdf");
engine.CreateDatabase();
}

conn = new SqlCeConnection (@"Data Source = \My Documents\MSFA.sdf");
conn.Open();

SqlCeCommand cmd = conn.CreateCommand();

cmd.CommandText =
"CREATE TABLE Schedule (Date NVARCHAR(15), Time NVARCHAR(15), Task NVARCHAR(15))";
cmd.ExecuteNonQuery();

cmd.CommandText =
"INSERT INTO Schedule (Date, Time, Task)" +
"VALUES ('3/18/2004', '08.00 am', 'Do BCP')";
cmd.ExecuteNonQuery();

cmd.CommandText =
"INSERT INTO Schedule (Date, Time, Task)" +
"VALUES ('3/18/2004', '08.30 am', 'Sleep')";
cmd.ExecuteNonQuery();

cmd.CommandText =
"INSERT INTO Schedule (Date, Time, Task)" +
"VALUES ('3/19/2004', '09.00 am', 'Do')";
cmd.ExecuteNonQuery();

}

catch (SqlCeException){}


finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}

string cn = @"Data Source = \My Documents\MSFA.sdf";

using(SqlCeConnection cn1 = new SqlCeConnection(cn))
{
cn1.Open();
string select = "SELECT * FROM Schedule";
SqlCeDataAdapter da = new SqlCeDataAdapter();

da.MissingMappingAction = MissingMappingAction.Passthrough;
da.MissingSchemaAction = MissingSchemaAction.Add;
da.SelectCommand = new SqlCeCommand(select, cn1);

ds = new DataSet();
da.Fill(ds, "Schedule");
dt = ds.Tables["Schedule"];
g1.DataSource = dt;
txtDate.DataBindings.Clear();
txtDate.DataBindings.Add("Text", dt, "Date");
txtTime.DataBindings.Clear();
txtTime.DataBindings.Add("Text", dt, "Time");
txtTask.DataBindings.Clear();
txtTask.DataBindings.Add("Text", dt, "Task");
}

}


private void btnRetrieve_Click(object sender, System.EventArgs e)
{
SqlCeConnection conn = null;
SqlCeCommand comm = null;
using( conn = new SqlCeConnection(cn))
{
conn.Open();
string q4 = "SELECT * FROM Schedule";
SqlCeDataReader dr = null;
try
{
comm = new SqlCeCommand(q4, conn);
comm.CommandType = CommandType.Text;
dr = comm.ExecuteReader(CommandBehavior.Default);

while(dr.Read())
{
MessageBox.Show(string.Format(str, dr.GetString(0),dr.GetString(1), dr.GetString(2)));
}
}

catch (SqlCeException) {}

finally
{
if (comm != null)
comm.Dispose();

if (dr != null)
dr.Close();
}
}

}
}
}
 
G

Guest

Thanks for reply.
But can u please let me know where should I put the Debug.Assert(ds.HasChanges)
Thanks
 
G

Guest

I've try it but it does not work and no error at all.
When I update the database, it does update the data table but after I update, I retrieve all the data from the table again but it does not display the updated value. Do I need to use the move next method like what we used in ado control ???

I've refer to lots of books, artical, online tutorial all stated after call the data adapter update the dataset it will update the source. From my understanding, update in ado.net will perform all "insert, delete, and update" function am I right ???

if you free, hopefully you can check the code I post at first time, I think you can directly run it after u create the GUI

Below Code I put in the update Button:

cmdSelect = cnn.CreateCommand();
cmdSelect.CommandText = "SELECT * FROM Schedule";
da.SelectCommand = cmdSelect;

cmdUpdate = cnn.CreateCommand();
cmdUpdate.CommandText = "UPDATE Schedule SET DATE = ?,Time = ?, Task = ? " +
"WHERE Date = ? AND Time = ? AND Task = ? ";
SqlCeParameterCollection pc = cmdUpdate.Parameters;
pc.Add("Date_New", SqlDbType.NVarChar,15, "Date");
pc.Add("Time_New", SqlDbType.NVarChar,15, "Time");
pc.Add("Task_New", SqlDbType.NVarChar,15, "Task");

prm = cmdUpdate.Parameters.Add("Date_Orig", SqlDbType.NVarChar, 15, "Date");
prm = cmdUpdate.Parameters.Add("Time_Orig", SqlDbType.NVarChar, 15, "Time");
prm = cmdUpdate.Parameters.Add("Task_Orig", SqlDbType.NVarChar, 15, "Task");
prm.SourceVersion = DataRowVersion.Original;
da.UpdateCommand = cmdUpdate;

cmdDelete = cnn.CreateCommand();
cmdDelete.CommandText = "DELETE FROM Schedule WHERE Date = ? AND Time = ? AND Task = ? ";
prm = cmdDelete.Parameters.Add("Date", SqlDbType.NVarChar, 15, "Date");
prm = cmdDelete.Parameters.Add("Time", SqlDbType.NVarChar, 15, "Time");
prm = cmdDelete.Parameters.Add("Task", SqlDbType.NVarChar, 15, "Task");
prm.SourceVersion = DataRowVersion.Original;
da.DeleteCommand = cmdDelete;

cmdInsert = cnn.CreateCommand();
cmdInsert.CommandText = "INSERT INTO Schedule(Date, Time, Task) VALUES(?, ?, ?)";
prm = cmdInsert.Parameters.Add("Date", SqlDbType.NVarChar, 15, "Date");
prm = cmdInsert.Parameters.Add("Time", SqlDbType.NVarChar, 15, "Time");
prm = cmdInsert.Parameters.Add("Task", SqlDbType.NVarChar, 15, "Task");
da.InsertCommand = cmdInsert;


Below code I put it in the save button once I click on it the datatable value will change:
da.Update(ds, "Schedule");
 
W

William Ryan eMVP

Liana:

First, I think the problem is that your code for btn_Update doesn't call
DataAdapter.Update... Show is calling it so it may be a problem with the
wrong button being clicked. Your btn_Update click event doesn't really do
anything but set some settings. However, btn_show calls update, but, if if
the settings aren't in place, it's not going to do anything.

The other problem I see is scripting a Create Table each time the form
loads. You are eating exceptions all over the place without any
notification anywhere, so you are almost definitely throwing exceptions that
you don't know about. If the table already exists, as soon as you call the
first ExecutNonQuery you are going down to the catch block and bypassing
everything else.

If you catch an exception, do something with it. This is really dangerous
to just ignore it and I'm positive you are throwing some exceptions.

Also, in the end of form load, you open your connection but never close it.
This is going to cause a problem because other connections won't be able to
be made. If you are using a DataAdapter, don't open and close your
connections manually unless you have a good reason to, you'll invariably
forget to do it somewhere.

If you are using the command methods, ExecuteReader, ExecuteNonQuery,
ExecuteScalar etc, then you have to open and close it.

Anyway, there's so many things here that are problems. The first step is to
put in either MessageBox.Show(ex.ToString());

in your exception blocks,. Also, use catch(SqlCeException ex) or some other
variable so you can extract other information.

You don't need to use MoveNext, completely different beast here. Here's the
deal, if you edit a row in a datatable, and have correct update logic, it
will be marked Modified, Deleted, Inserted corresponding to what was done.
If the rowstate property of the rows isn't changed, you can call DA.UPdate
all year and nothing will happen. That's why I asked you to use the
Assertion (Debug.Assert(DataSetName.HasChanges());

because if the assertion fails, then the problem is simple that the rows
aren't being marked as modified for some reason. If this is the case, it's
probably a problem with the databinding or the way you are editing the data.

On the other hand, if the dataset HasChanges, then the problem is going to
be with things like being able to make a connection or the logic in the
update/insert/delete statement.

I can't tell really without knowing if the changes are being marked.

I'm also wondering what is the purpose of retrieve?

Anyway, can you fill in the catch blocks and tell me if the dataset has
changes? That'll help us eliminate problems one at a time.

HTH,

Bill
Lianna said:
I've try it but it does not work and no error at all.
When I update the database, it does update the data table but after I
update, I retrieve all the data from the table again but it does not display
the updated value. Do I need to use the move next method like what we used
in ado control ???
I've refer to lots of books, artical, online tutorial all stated after
call the data adapter update the dataset it will update the source. From my
understanding, update in ado.net will perform all "insert, delete, and
update" function am I right ???
if you free, hopefully you can check the code I post at first time, I
think you can directly run it after u create the GUI
 
G

Guest

Thanks a million. I really appreciate that you willing to help me all this while. However, since the scenario seems complicated, I’ve decide to code the program again. But First I would describe my scenario again and then would like to clarify few questions

Scenario:
I want to write a simple program that allows users to view their daily schedule, and they can update the existing schedule, add new schedule and delete schedule made

1. If I put the create table code in “form_load†does it correct ?? I’ve followed you
suggestion and catch the exception with below code:

catch (SqlCeException ex

for(int cu = 0; cu < ex.Errors.Count; ++cu

MessageBox.Show("Error:" + ex.Errors[cu].ToString()+ "\n")



This code does show error message that the table I create already
exists. So I’ve modified the code

if (! File.Exists (@"\My Documents\MSFA.sdf")

SqlCeEngine engine = new SqlCeEngine
@"Data Source = \My Documents\MSFA.sdf")
engine.CreateDatabase()

els

File.Delete(@"\My Documents\MSFA.sdf")
SqlCeEngine engine = new SqlCeEngine
@"Data Source = \My Documents\MSFA.sdf")
engine.CreateDatabase()



And I do close the connection which is shown in the “finallyâ€
statement. Or it’s advisable to close the connection once create th
table. If I put before “catchâ€, does it work ??


2. Does the way I bind the control is correct ?? I bind the contro
with following code and the binding code is put in the “form_loadâ€.

SqlCeDataAdapter da = new SqlCeDataAdapter()
DataSet ds = new DataSet()
DataTable dt = new DataTable()
da.Fill(ds, "Schedule")
dt = ds.Tables["Schedule"]
dataGrid.DataSource = dt
txtDate.DataBindings.Clear()
txtDate.DataBindings.Add("Text", dt, "Date")
txtTime.DataBindings.Clear()
txtTime.DataBindings.Add("Text", dt, "Time")
txtTask.DataBindings.Clear()
txtTask.DataBindings.Add("Text", dt, "Task")


3. Where should I place the following DataAdapter command?? Is it als
put in “form_load†?? Is it necessary to have all this command i
order to update the data source ??

SelectCommand, UpdateCommand, InsertCommand and DeleteComman

Example
cmdUpdate = cnn.CreateCommand()
cmdUpdate.CommandText = "UPDATE Schedule SET DATE = @Date,Time =
@Time, Task = @Task WHERE Date = @Date AND Time = @Time AND Task
@Task "

prm = cmdUpdate.Parameters.Add("@Date", SqlDbType.NVarChar, 0
"Date")
prm = cmdUpdate.Parameters.Add("@Time", SqlDbType.NVarChar, 0
"Time")
prm = cmdUpdate.Parameters.Add("@Task", SqlDbType.NVarChar, 0,
"Task")
prm.SourceVersion = DataRowVersion.Original
da.UpdateCommand = cmdUpdate

4. To check whether the dataset is updated or not is it I can use following code: If not then how can I know the row is change ??. In my existing program, I try to put it after call the -- da.update(ds, "Schedule") and the result show the dataset does not change

if(ds.HasChange()

// Do somethin
}

5. I put the btnRetreive because I think after I call the da.Update(ds,â€Scheduleâ€) then I check whether the
data source is updated by click the retrieve button and select all the row from the table again. Does i
logic ?

6. Actually what I need in the “UpdateButton_Click†??? Is it just need the following code ?

try
da.Update(ds, “Scheduleâ€)
ds.AcceptChanges()

catch (Exception ex)

// Do somethin
}

7. The “Assertion (Debug.Assert(ds.HasChanges())); “ code that you ask me try does not work, the syste
display – “The type or namespace name 'Debug' could not be found (are you missing a using directive o
an assembly reference?)â€
 
W

William Ryan eMVP

1) When the app starts, I'd check to see if the table exists. Creating a
database/table every time the app loads is most likely unnecessary. If you
have data in the database from the last session, you'll delete it under your
scenario, and if you don't need to persist the data, then there's better
ways than handle data than SqlCe. You could create a datatable/dataset
locally and just never serialize it so it goes away when the app does.
That'd probably be a preferable method to creating the database each time
and deleting it beforehand if it does.

As far as the connection..think of it this way. If you put connection close
anywhere in your try block and you throw an exception, you'll never close
the connection. If you put it in the catch block, you'll only close it if
you throw an exception. Neither of which is desireable. So, here's what I
recommend. In the finally block, use a test if(cn.State <>
ConnectionState.Closed){cn.Close();} Now, you can still close it
immediately when you are finished with the connection but this will make
sure it's closed. If you are using a DataAdapter, I'd highly recommend
letting it open and close itself so you don't accidentally forget to close
it. However, I'd still use the finally block in case something blows up.
with the command object methods, you have no choice but to open the
connection manually, and consequently, you're responsible for closing it.

2) Yes
3) You can do it in form_load, that's fine. Remember that this isn't doing
anything with the data adapter other than setting it's properties. It only
needs to happen once, so Form_Load is fine for this
4) No, all that HasChanges tells you is if the dataset has changes. If it
doesn't , then you can call update all year and nothign will happen.
However, if it does, you can call update and hopefully you're changes will
be commmited. They may not though because of many things, like no available
connection. Usually though, everything will be fine.

DataAdapter.Update returns an Integer value indicating how many rows were
changed in the DB. So, something like int i = DataAdapter.Update(dataSet,
TableName);
if i > 0 it worked.
5) Unnecessary. SqlCE isn't going to be updated by someone else other than
the user. So, all of the changes will be reflected locally. If your update
fails, and you repopulate it, you'll overwrite your changes. Update only
sends the changes back to the database, it doesn't pull any new values back
unless your code is such that it fires additional select statements.
6) Right
7) add using System.Diagnostics; at the top of your code.

Let me know how it goes and if you have any problems.

Cheers,

Bill

Lianna said:
Thanks a million. I really appreciate that you willing to help me all this
while. However, since the scenario seems complicated, I've decide to code
the program again. But First I would describe my scenario again and then
would like to clarify few questions.
Scenario:
I want to write a simple program that allows users to view their daily
schedule, and they can update the existing schedule, add new schedule and
delete schedule made.
1. If I put the create table code in "form_load" does it correct ?? I've followed your
suggestion and catch the exception with below code:

catch (SqlCeException ex)
{
for(int cu = 0; cu < ex.Errors.Count; ++cu)
{
MessageBox.Show("Error:" + ex.Errors[cu].ToString()+ "\n");
}
}

This code does show error message that the table I create already
exists. So I've modified the code:

if (! File.Exists (@"\My Documents\MSFA.sdf"))
{
SqlCeEngine engine = new SqlCeEngine (
@"Data Source = \My Documents\MSFA.sdf");
engine.CreateDatabase();
}
else
{
File.Delete(@"\My Documents\MSFA.sdf");
SqlCeEngine engine = new SqlCeEngine (
@"Data Source = \My Documents\MSFA.sdf");
engine.CreateDatabase();
}


And I do close the connection which is shown in the "finally"
statement. Or it's advisable to close the connection once create the
table. If I put before "catch", does it work ???



2. Does the way I bind the control is correct ?? I bind the control
with following code and the binding code is put in the "form_load".


SqlCeDataAdapter da = new SqlCeDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
da.Fill(ds, "Schedule");
dt = ds.Tables["Schedule"];
dataGrid.DataSource = dt;
txtDate.DataBindings.Clear();
txtDate.DataBindings.Add("Text", dt, "Date");
txtTime.DataBindings.Clear();
txtTime.DataBindings.Add("Text", dt, "Time");
txtTask.DataBindings.Clear();
txtTask.DataBindings.Add("Text", dt, "Task");



3. Where should I place the following DataAdapter command?? Is it also
put in "form_load" ?? Is it necessary to have all this command in
order to update the data source ??

SelectCommand, UpdateCommand, InsertCommand and DeleteCommand

Example:
cmdUpdate = cnn.CreateCommand();
cmdUpdate.CommandText = "UPDATE Schedule SET DATE = @Date,Time =
@Time, Task = @Task WHERE Date = @Date AND Time = @Time AND Task =
@Task ";

prm = cmdUpdate.Parameters.Add("@Date", SqlDbType.NVarChar, 0,
"Date");
prm = cmdUpdate.Parameters.Add("@Time", SqlDbType.NVarChar, 0,
"Time");
prm = cmdUpdate.Parameters.Add("@Task", SqlDbType.NVarChar, 0,
"Task");
prm.SourceVersion = DataRowVersion.Original;
da.UpdateCommand = cmdUpdate;


4. To check whether the dataset is updated or not is it I can use
following code: If not then how can I know the row is change ??. In my
existing program, I try to put it after call the -- da.update(ds,
"Schedule") and the result show the dataset does not change.
if(ds.HasChange())
{
// Do something
}

5. I put the btnRetreive because I think after I call the da.Update(ds,"
Schedule") then I check whether the
data source is updated by click the retrieve button and select all the
row from the table again. Does it
logic ??

6. Actually what I need in the "UpdateButton_Click" ??? Is it just need the following code ??

try{
da.Update(ds, "Schedule");
ds.AcceptChanges();
}
catch (Exception ex)
{
// Do something
}

7. The "Assertion (Debug.Assert(ds.HasChanges())); " code that you ask me try does not work, the system
display - "The type or namespace name 'Debug' could not be found (are
you missing a using directive or
 
G

Guest

Yes William,

In answer 4, - what means "call update all year and nothing will happen" ??

In answer 5, - I'm not really understand what you means "unless your code is such that it fires additional select statements." In addition, if I have update the existing appointment and I close the application and open again will the updated data still exists. How to get the updated data ?? Cause in my program, I've four tab

- 1st tab display the today appointmen

- 2nd tab allows user to view their appointment by click on the dataTimePicker. Each time the date change, the program
will retreive the appointment for that particular date from the local database, and display it in a data grid
User can update the appointment by click on the datagrid, and the update form will displa

- 3rd tab allows user to add new appointment. This part there is no problem as I use sql to insert the value and cal
"ExecuteNonQuery( )" to commit the action. Then I go to 2nd tab and select the date that the appointment I just insert,
it display the appointment made

- 4th tab is used to delete the existing appointment. This part face the same problem. But I think if manage to solve th
update problem, this will solve also.

Thanks i will try to solved the problem by myself first, if stud then will let you know thanksss

----- William Ryan eMVP wrote: ----

1) When the app starts, I'd check to see if the table exists. Creating
database/table every time the app loads is most likely unnecessary. If yo
have data in the database from the last session, you'll delete it under you
scenario, and if you don't need to persist the data, then there's bette
ways than handle data than SqlCe. You could create a datatable/datase
locally and just never serialize it so it goes away when the app does
That'd probably be a preferable method to creating the database each tim
and deleting it beforehand if it does

As far as the connection..think of it this way. If you put connection clos
anywhere in your try block and you throw an exception, you'll never clos
the connection. If you put it in the catch block, you'll only close it i
you throw an exception. Neither of which is desireable. So, here's what
recommend. In the finally block, use a test if(cn.State <
ConnectionState.Closed){cn.Close();} Now, you can still close i
immediately when you are finished with the connection but this will mak
sure it's closed. If you are using a DataAdapter, I'd highly recommen
letting it open and close itself so you don't accidentally forget to clos
it. However, I'd still use the finally block in case something blows up
with the command object methods, you have no choice but to open th
connection manually, and consequently, you're responsible for closing it

2) Ye
3) You can do it in form_load, that's fine. Remember that this isn't doin
anything with the data adapter other than setting it's properties. It onl
needs to happen once, so Form_Load is fine for thi
4) No, all that HasChanges tells you is if the dataset has changes. If i
doesn't , then you can call update all year and nothign will happen
However, if it does, you can call update and hopefully you're changes wil
be commmited. They may not though because of many things, like no availabl
connection. Usually though, everything will be fine

DataAdapter.Update returns an Integer value indicating how many rows wer
changed in the DB. So, something like int i = DataAdapter.Update(dataSet
TableName)
if i > 0 it worked
5) Unnecessary. SqlCE isn't going to be updated by someone else other tha
the user. So, all of the changes will be reflected locally. If your updat
fails, and you repopulate it, you'll overwrite your changes. Update onl
sends the changes back to the database, it doesn't pull any new values bac
unless your code is such that it fires additional select statements
6) Right
7) add using System.Diagnostics; at the top of your code.

Let me know how it goes and if you have any problems.

Cheers,

Bill

Lianna said:
Thanks a million. I really appreciate that you willing to help me all this
while. However, since the scenario seems complicated, I've decide to code
the program again. But First I would describe my scenario again and then
would like to clarify few questions.
I want to write a simple program that allows users to view their daily
schedule, and they can update the existing schedule, add new schedule and
delete schedule made.
1. If I put the create table code in "form_load" does it correct ?? I've
followed your
suggestion and catch the exception with below code:
catch (SqlCeException ex)
{
for(int cu = 0; cu < ex.Errors.Count; ++cu)
{
MessageBox.Show("Error:" + ex.Errors[cu].ToString()+ "\n");
}
}
This code does show error message that the table I create already
exists. So I've modified the code:
if (! File.Exists (@"\My Documents\MSFA.sdf"))
{
SqlCeEngine engine = new SqlCeEngine (
@"Data Source = \My Documents\MSFA.sdf");
engine.CreateDatabase();
}
else
{
File.Delete(@"\My Documents\MSFA.sdf");
SqlCeEngine engine = new SqlCeEngine (
@"Data Source = \My Documents\MSFA.sdf");
engine.CreateDatabase();
}statement. Or it's advisable to close the connection once create the
table. If I put before "catch", does it work ???DataSet ds = new DataSet();
DataTable dt = new DataTable();
da.Fill(ds, "Schedule");
dt = ds.Tables["Schedule"];
dataGrid.DataSource = dt;
txtDate.DataBindings.Clear();
txtDate.DataBindings.Add("Text", dt, "Date");
txtTime.DataBindings.Clear();
txtTime.DataBindings.Add("Text", dt, "Time");
txtTask.DataBindings.Clear();
txtTask.DataBindings.Add("Text", dt, "Task");put in "form_load" ?? Is it necessary to have all this command in
order to update the data source ??
SelectCommand, UpdateCommand, InsertCommand and DeleteCommand
Example:
cmdUpdate = cnn.CreateCommand();
cmdUpdate.CommandText = "UPDATE Schedule SET DATE = @Date,Time =
@Time, Task = @Task WHERE Date = @Date AND Time = @Time AND Task =
@Task ";
prm = cmdUpdate.Parameters.Add("@Date", SqlDbType.NVarChar, 0,
"Date");
prm = cmdUpdate.Parameters.Add("@Time", SqlDbType.NVarChar, 0,
"Time");
prm = cmdUpdate.Parameters.Add("@Task", SqlDbType.NVarChar, 0,
"Task");
prm.SourceVersion = DataRowVersion.Original;
da.UpdateCommand = cmdUpdate;
following code: If not then how can I know the row is change ??. In my
existing program, I try to put it after call the -- da.update(ds,
"Schedule") and the result show the dataset does not change.
{
// Do something
}
Schedule") then I check whether the
data source is updated by click the retrieve button and select all the
row from the table again. Does it
logic ??
da.Update(ds, "Schedule");
ds.AcceptChanges();
}
catch (Exception ex)
{
// Do something
} try does not work, the system
display - "The type or namespace name 'Debug' could not be found (are
you missing a using directive or
 
G

Guest

I've re-code the program as follow

1. In Form, cnasists of one datagrid named "g1", three textbox that bind to the dataTable to display the Date, Time, and
Task. Lastly one update button. I declared the DataTabel -> "dt", DataSet -> "ds", and SqlCeDataAdapter -> "da" and
put it above the constructor (Note: If I'm not mistaken, its called global variable right !!)

2. I put the following code at "Form_Load". Thus if file not exists, will call the "CreateTable" function. Is it ok to do like
this ??? Cause there is no exception throw. I closed the connection in the “Create Table†function as you say, I’m not us
data Adapter.

SqlCeConnection conn = null
tr

if (! File.Exists (@"\My Documents\MSFA.sdf")

CreateTable(conn)

els



catch (SqlCeException ex

for(int cu = 0; cu < ex.Errors.Count; ++cu

MessageBox.Show("Error:" + ex.Errors[cu].ToString()+ "\n")



3. For the DataAdapter command (the code is exactly the same without changes), I put it at “Form_Load†and I bind th
control as well. Is it ok to bind the control at “Form_Loadâ€

4. In UpdateButton_Click, I put the following code. It display the “fail message†and “No message†then I try to add th
Debug.assert(ds.HasChanges()) as shown in (i) it shows the message – refer to “message 1â€

tr

(i) Debug.Assert(ds.HasChanges())
da.Update(ds, "Schedule")
ds.AcceptChanges()
int i = da.Update(ds, "Schedule")
if(i > 0

MessageBox.Show("Updated")

els

MessageBox.Show("fail")


if(ds.HasChanges()

MessageBox.Show("Yes")

els

MessageBox.Show("No")
da.Update(ds, "Schedule")
ds.AcceptChanges()


catch (SqlCeException ex3

for(int cu = 0; cu < ex3.Errors.Count; ++cu

MessageBox.Show("Error:" + ex3.Errors[cu].ToString()+ "\n")



“Message 1: â€

TraceInternal::AssertFailur
TraceInternal::Fail+0x1
TraceInternal::Assert+0x
Debug::Assert+0x
Form1::btnUpdate_Click+0x1
Control::OnClick+0x1
Button::OnClick+0x3
ButtonBase::OnClick+WinProc+0x
Control::_InternalWnProc+0x
EVL::EnterMainLoo
Application::Run+0x1
Form1::Main+0x

Thanks "_
 
W

William Ryan eMVP

1) If you call Update, and the rowstate of all your rows is unchanged (ie
HasChanges = false), then there's nothing to submit to the database. The
way the dataadapter works is it iterations through the rows collection for
the changed rows, calling the DataAdapter's Update command for all rows
marked as Modified, Delete for each of the ones marked Deleted, and Insert
for each one that's inserted.

So, if you don't have any changes, it's the equivalent of putting calling
the Update commandtext in the middle of a loop that never iteraties.
2) You can set up your Update Statement in a way that at the end, it calls
an additional select statement. This is usually done to retrieve Indentity
values that are only assigned by the DB once the update command is executed.
If you go into the dataadapter configuration wizard, and you select Advanced
Options in the part of the wizard where you select the tables, you'll see an
option called Refresh DataSet. This is on by default. If this is checked,
then your Insert Command for instance will have two statements, The insert
command a ";" and a Seelct command. The mappings will take care of updating
the values.

The main problem you are having is where you are calling update. If the
DataSet hasChanges, the changes should be submitted if your command logic is
correct. However this will only happen if you call Update.

Let me look through the new code a little more and see if I can write it for
you to get you started.

Cheers,

Bill
Lianna said:
Yes William,

In answer 4, - what means "call update all year and nothing will happen" ???

In answer 5, - I'm not really understand what you means "unless your code
is such that it fires additional select statements." In addition, if I have
update the existing appointment and I close the application and open again
will the updated data still exists. How to get the updated data ?? Cause in
my program, I've four tab
- 1st tab display the today appointment

- 2nd tab allows user to view their appointment by click on the
dataTimePicker. Each time the date change, the program
will retreive the appointment for that particular date from the local
database, and display it in a data grid.
User can update the appointment by click on the datagrid, and the update form will display

- 3rd tab allows user to add new appointment. This part there is no
problem as I use sql to insert the value and call
"ExecuteNonQuery( )" to commit the action. Then I go to 2nd tab and
select the date that the appointment I just insert,
it display the appointment made.

- 4th tab is used to delete the existing appointment. This part face the
same problem. But I think if manage to solve the
update problem, this will solve also.


Thanks i will try to solved the problem by myself first, if stud then will let you know thankssss

----- William Ryan eMVP wrote: -----

1) When the app starts, I'd check to see if the table exists. Creating a
database/table every time the app loads is most likely unnecessary. If you
have data in the database from the last session, you'll delete it under your
scenario, and if you don't need to persist the data, then there's better
ways than handle data than SqlCe. You could create a datatable/dataset
locally and just never serialize it so it goes away when the app does.
That'd probably be a preferable method to creating the database each time
and deleting it beforehand if it does.

As far as the connection..think of it this way. If you put connection close
anywhere in your try block and you throw an exception, you'll never close
the connection. If you put it in the catch block, you'll only close it if
you throw an exception. Neither of which is desireable. So, here's what I
recommend. In the finally block, use a test if(cn.State <>
ConnectionState.Closed){cn.Close();} Now, you can still close it
immediately when you are finished with the connection but this will make
sure it's closed. If you are using a DataAdapter, I'd highly recommend
letting it open and close itself so you don't accidentally forget to close
it. However, I'd still use the finally block in case something blows up.
with the command object methods, you have no choice but to open the
connection manually, and consequently, you're responsible for closing it.

2) Yes
3) You can do it in form_load, that's fine. Remember that this isn't doing
anything with the data adapter other than setting it's properties. It only
needs to happen once, so Form_Load is fine for this
4) No, all that HasChanges tells you is if the dataset has changes. If it
doesn't , then you can call update all year and nothign will happen.
However, if it does, you can call update and hopefully you're changes will
be commmited. They may not though because of many things, like no available
connection. Usually though, everything will be fine.

DataAdapter.Update returns an Integer value indicating how many rows were
changed in the DB. So, something like int i = DataAdapter.Update(dataSet,
TableName);
if i > 0 it worked.
5) Unnecessary. SqlCE isn't going to be updated by someone else other than
the user. So, all of the changes will be reflected locally. If your update
fails, and you repopulate it, you'll overwrite your changes. Update only
sends the changes back to the database, it doesn't pull any new values back
unless your code is such that it fires additional select statements.
6) Right
7) add using System.Diagnostics; at the top of your code.

Let me know how it goes and if you have any problems.

Cheers,

Bill

Lianna said:
Thanks a million. I really appreciate that you willing to help me
all this
while. However, since the scenario seems complicated, I've decide to code
the program again. But First I would describe my scenario again and then
would like to clarify few questions.
I want to write a simple program that allows users to view their
daily
schedule, and they can update the existing schedule, add new schedule and
delete schedule made. ?? I've
followed your
suggestion and catch the exception with below code:
catch (SqlCeException ex)
{
for(int cu = 0; cu < ex.Errors.Count; ++cu)
{
MessageBox.Show("Error:" + ex.Errors[cu].ToString()+ "\n");
}
}
This code does show error message that the table I create
already
exists. So I've modified the code:
if (! File.Exists (@"\My Documents\MSFA.sdf"))
{
SqlCeEngine engine = new SqlCeEngine (
@"Data Source = \My Documents\MSFA.sdf");
engine.CreateDatabase();
}
else
{
File.Delete(@"\My Documents\MSFA.sdf");
SqlCeEngine engine = new SqlCeEngine (
@"Data Source = \My Documents\MSFA.sdf");
engine.CreateDatabase();
}
And I do close the connection which is shown in the "finally"
statement. Or it's advisable to close the connection once create the
table. If I put before "catch", does it work ???
2. Does the way I bind the control is correct ?? I bind the
control
with following code and the binding code is put in the "form_load".
SqlCeDataAdapter da = new SqlCeDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();
da.Fill(ds, "Schedule");
dt = ds.Tables["Schedule"];
dataGrid.DataSource = dt;
txtDate.DataBindings.Clear();
txtDate.DataBindings.Add("Text", dt, "Date");
txtTime.DataBindings.Clear();
txtTime.DataBindings.Add("Text", dt, "Time");
txtTask.DataBindings.Clear();
txtTask.DataBindings.Add("Text", dt, "Task");
3. Where should I place the following DataAdapter command?? Is
it also
put in "form_load" ?? Is it necessary to have all this command in
order to update the data source ??
SelectCommand, UpdateCommand, InsertCommand and DeleteCommand
Example:
cmdUpdate = cnn.CreateCommand();
cmdUpdate.CommandText = "UPDATE Schedule SET DATE = @Date,Time =
@Time, Task = @Task WHERE Date = @Date AND Time = @Time AND Task =
@Task ";
prm = cmdUpdate.Parameters.Add("@Date", SqlDbType.NVarChar, 0,
"Date");
prm = cmdUpdate.Parameters.Add("@Time", SqlDbType.NVarChar, 0,
"Time");
prm = cmdUpdate.Parameters.Add("@Task", SqlDbType.NVarChar, 0,
"Task");
prm.SourceVersion = DataRowVersion.Original;
da.UpdateCommand = cmdUpdate;
4. To check whether the dataset is updated or not is it I can use
following code: If not then how can I know the row is change ??. In my
existing program, I try to put it after call the -- da.update(ds,
"Schedule") and the result show the dataset does not change.
{
// Do something
}
da.Update(ds,"
Schedule") then I check whether the
data source is updated by click the retrieve button and select
all the
row from the table again. Does it
just need
the following code ??
da.Update(ds, "Schedule");
ds.AcceptChanges();
}
catch (Exception ex)
{
// Do something
}
ask me
try does not work, the system
display - "The type or namespace name 'Debug' could not be
found (are
you missing a using directive or
an assembly reference?)"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top