T
Topeak
I want to transfer data from sqlserver to local access database ,
and i use dataset.merger() method , but i find the accessDS's datarow state
keeps unchanged !
so i have to change some unimportant column's data,
but it throws exception "No value given for one or more required parameters.
"
The access table columns allow null ,except key column "unitcode"
Help Me!!!!
DataSet dsSqlServer=BasicConn.GetDataSet("select * from
hrmis_t_unit_base","unitBase",objConn);
OleDbCommand cmd=new OleDbCommand();
cmd.Connection=Form1.connAccess;
try
{
cmd.CommandText="delete from hrmis_t_unit_base";
cmd.ExecuteNonQuery();
OleDbDataAdapter myDA=new OleDbDataAdapter("select * from
hrmis_t_unit_base",Form1.connAccess);
OleDbCommandBuilder cb=new OleDbCommandBuilder(myDA);
// cb.QuotePrefix="[";
// cb.QuoteSuffix="]";
string strInsert=cb.GetInsertCommand().CommandText;
// strInsert="INSERT INTO hrmis_t_unit_base( unitcode , unitname ,
unitgrade , upunitcode , sequence, unitid , duty ) VALUES ( ? , ? , ? ,?, ?
, ? , ? )";
myDA.InsertCommand=new OleDbCommand(strInsert,Form1.connAccess);
myDA.UpdateCommand=new
OleDbCommand(cb.GetUpdateCommand().CommandText,Form1.connAccess);
myDA.DeleteCommand=new
OleDbCommand(cb.GetDeleteCommand().CommandText,Form1.connAccess);
myDA.MissingSchemaAction=MissingSchemaAction.AddWithKey;
DataSet accessDS=new DataSet();
myDA.Fill(accessDS,"unitBase");
accessDS.Merge(dsSqlServer,true);
for(int i=0;i<accessDS.Tables["unitBase"].Rows.Count;i++)
{
accessDS.Tables["unitBase"].Rows["sequence"]=0;
}
try
{
myDA.Update(accessDS.Tables["unitBase"]);
accessDS.Tables["unitBase"].AcceptChanges();
MessageBox.Show("Synchronise Access Table Success!");
}
catch(Exception exx)
{
throw new Exception(exx.Message ,exx);
}
}
catch(Exception EX)
{
MessageBox.Show("¸üÐÂÊý¾Ý¿â³ö´í!"+EX.Message );
}
finally
{
}
and i use dataset.merger() method , but i find the accessDS's datarow state
keeps unchanged !
so i have to change some unimportant column's data,
but it throws exception "No value given for one or more required parameters.
"
The access table columns allow null ,except key column "unitcode"
Help Me!!!!
DataSet dsSqlServer=BasicConn.GetDataSet("select * from
hrmis_t_unit_base","unitBase",objConn);
OleDbCommand cmd=new OleDbCommand();
cmd.Connection=Form1.connAccess;
try
{
cmd.CommandText="delete from hrmis_t_unit_base";
cmd.ExecuteNonQuery();
OleDbDataAdapter myDA=new OleDbDataAdapter("select * from
hrmis_t_unit_base",Form1.connAccess);
OleDbCommandBuilder cb=new OleDbCommandBuilder(myDA);
// cb.QuotePrefix="[";
// cb.QuoteSuffix="]";
string strInsert=cb.GetInsertCommand().CommandText;
// strInsert="INSERT INTO hrmis_t_unit_base( unitcode , unitname ,
unitgrade , upunitcode , sequence, unitid , duty ) VALUES ( ? , ? , ? ,?, ?
, ? , ? )";
myDA.InsertCommand=new OleDbCommand(strInsert,Form1.connAccess);
myDA.UpdateCommand=new
OleDbCommand(cb.GetUpdateCommand().CommandText,Form1.connAccess);
myDA.DeleteCommand=new
OleDbCommand(cb.GetDeleteCommand().CommandText,Form1.connAccess);
myDA.MissingSchemaAction=MissingSchemaAction.AddWithKey;
DataSet accessDS=new DataSet();
myDA.Fill(accessDS,"unitBase");
accessDS.Merge(dsSqlServer,true);
for(int i=0;i<accessDS.Tables["unitBase"].Rows.Count;i++)
{
accessDS.Tables["unitBase"].Rows["sequence"]=0;
}
try
{
myDA.Update(accessDS.Tables["unitBase"]);
accessDS.Tables["unitBase"].AcceptChanges();
MessageBox.Show("Synchronise Access Table Success!");
}
catch(Exception exx)
{
throw new Exception(exx.Message ,exx);
}
}
catch(Exception EX)
{
MessageBox.Show("¸üÐÂÊý¾Ý¿â³ö´í!"+EX.Message );
}
finally
{
}