Hi,
I have a situation in where i have two instances of SQL server, the first is
our Production Environment, the second is our Development environment. Both
servers contain the same databases but I need to write a utility that can
transfer a row of data from the Production to the Development servers.
I wrote the code below, which doesn't error...but it doesn't work...no data
is updated. This is very odd because I can see that both of the datarows
contain the correct value when I check in Debug mode, it just isn't updating
the database.
i have two questions:
1) What am I missing that is causing the script not to work?
2) With respect to a dataset how can I get at the value of a specific
Row/Column?
Thanks for any help!
Ron
SqlConnection cnProductionSQL = new SqlConnection(" Data Source=SQLSVR01 ;
Integrated Security=SSPI; Initial Catalog=Master" );
cnProductionSQL .Open();
SqlConnection cnDevelopmentSQ L = new SqlConnection(" Data Source=SQLSVR02 ;
Integrated Security=SSPI; Initial Catalog=Master" );
cnDevelopmentSQ L.Open();
String strProductionSQ L = "SELECT * FROM [Global].[dbo].[Companies] WHERE
CompanyID ='" + strSQLDestDatab ase + "'";
SqlDataAdapter daProduction = new SqlDataAdapter( strProductionSQ L,
cnProductionSQL );
DataSet dsProduction = new DataSet();
daProduction.Fi ll(dsProduction ,"Companies" );
String strDevelopmentS QL = "SELECT * FROM [Global].[dbo].[Companies] WHERE
CompanyID ='" + strSQLDestDatab ase + "'";
SqlDataAdapter daDevelopment = new SqlDataAdapter( strDevelopmentS QL,
cnDevelopmentSQ L);
DataSet dsDevelopment = new DataSet();
daDevelopment.F ill(dsDevelopme nt,"Companies") ;
if (dsProduction.T ables["Companies"].Rows.Count > 0)
{
DataRow drProd;
DataRow drDev;
drProd = dsProduction.Ta bles["Companies"].Rows[0];
if (dsDevelopment. Tables["Companies"].Rows.Count > 0)
{
drDev = dsDevelopment.T ables["Companies"].Rows[0];
drDev.BeginEdit ();
drDev = drProd;
drDev.EndEdit() ;
daDevelopment.U pdate(dsDevelop ment, "Companies" );
}else
{
//insert
}
}
I have a situation in where i have two instances of SQL server, the first is
our Production Environment, the second is our Development environment. Both
servers contain the same databases but I need to write a utility that can
transfer a row of data from the Production to the Development servers.
I wrote the code below, which doesn't error...but it doesn't work...no data
is updated. This is very odd because I can see that both of the datarows
contain the correct value when I check in Debug mode, it just isn't updating
the database.
i have two questions:
1) What am I missing that is causing the script not to work?
2) With respect to a dataset how can I get at the value of a specific
Row/Column?
Thanks for any help!
Ron
SqlConnection cnProductionSQL = new SqlConnection(" Data Source=SQLSVR01 ;
Integrated Security=SSPI; Initial Catalog=Master" );
cnProductionSQL .Open();
SqlConnection cnDevelopmentSQ L = new SqlConnection(" Data Source=SQLSVR02 ;
Integrated Security=SSPI; Initial Catalog=Master" );
cnDevelopmentSQ L.Open();
String strProductionSQ L = "SELECT * FROM [Global].[dbo].[Companies] WHERE
CompanyID ='" + strSQLDestDatab ase + "'";
SqlDataAdapter daProduction = new SqlDataAdapter( strProductionSQ L,
cnProductionSQL );
DataSet dsProduction = new DataSet();
daProduction.Fi ll(dsProduction ,"Companies" );
String strDevelopmentS QL = "SELECT * FROM [Global].[dbo].[Companies] WHERE
CompanyID ='" + strSQLDestDatab ase + "'";
SqlDataAdapter daDevelopment = new SqlDataAdapter( strDevelopmentS QL,
cnDevelopmentSQ L);
DataSet dsDevelopment = new DataSet();
daDevelopment.F ill(dsDevelopme nt,"Companies") ;
if (dsProduction.T ables["Companies"].Rows.Count > 0)
{
DataRow drProd;
DataRow drDev;
drProd = dsProduction.Ta bles["Companies"].Rows[0];
if (dsDevelopment. Tables["Companies"].Rows.Count > 0)
{
drDev = dsDevelopment.T ables["Companies"].Rows[0];
drDev.BeginEdit ();
drDev = drProd;
drDev.EndEdit() ;
daDevelopment.U pdate(dsDevelop ment, "Companies" );
}else
{
//insert
}
}
Comment