R
RSH
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 cnDevelopmentSQL = new SqlConnection("Data Source=SQLSVR02;
Integrated Security=SSPI; Initial Catalog=Master");
cnDevelopmentSQL.Open();
String strProductionSQL = "SELECT * FROM [Global].[dbo].[Companies] WHERE
CompanyID ='" + strSQLDestDatabase + "'";
SqlDataAdapter daProduction = new SqlDataAdapter(strProductionSQL,
cnProductionSQL);
DataSet dsProduction = new DataSet();
daProduction.Fill(dsProduction,"Companies");
String strDevelopmentSQL = "SELECT * FROM [Global].[dbo].[Companies] WHERE
CompanyID ='" + strSQLDestDatabase + "'";
SqlDataAdapter daDevelopment = new SqlDataAdapter(strDevelopmentSQL,
cnDevelopmentSQL);
DataSet dsDevelopment = new DataSet();
daDevelopment.Fill(dsDevelopment,"Companies");
if (dsProduction.Tables["Companies"].Rows.Count > 0)
{
DataRow drProd;
DataRow drDev;
drProd = dsProduction.Tables["Companies"].Rows[0];
if (dsDevelopment.Tables["Companies"].Rows.Count > 0)
{
drDev = dsDevelopment.Tables["Companies"].Rows[0];
drDev.BeginEdit();
drDev = drProd;
drDev.EndEdit();
daDevelopment.Update(dsDevelopment, "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 cnDevelopmentSQL = new SqlConnection("Data Source=SQLSVR02;
Integrated Security=SSPI; Initial Catalog=Master");
cnDevelopmentSQL.Open();
String strProductionSQL = "SELECT * FROM [Global].[dbo].[Companies] WHERE
CompanyID ='" + strSQLDestDatabase + "'";
SqlDataAdapter daProduction = new SqlDataAdapter(strProductionSQL,
cnProductionSQL);
DataSet dsProduction = new DataSet();
daProduction.Fill(dsProduction,"Companies");
String strDevelopmentSQL = "SELECT * FROM [Global].[dbo].[Companies] WHERE
CompanyID ='" + strSQLDestDatabase + "'";
SqlDataAdapter daDevelopment = new SqlDataAdapter(strDevelopmentSQL,
cnDevelopmentSQL);
DataSet dsDevelopment = new DataSet();
daDevelopment.Fill(dsDevelopment,"Companies");
if (dsProduction.Tables["Companies"].Rows.Count > 0)
{
DataRow drProd;
DataRow drDev;
drProd = dsProduction.Tables["Companies"].Rows[0];
if (dsDevelopment.Tables["Companies"].Rows.Count > 0)
{
drDev = dsDevelopment.Tables["Companies"].Rows[0];
drDev.BeginEdit();
drDev = drProd;
drDev.EndEdit();
daDevelopment.Update(dsDevelopment, "Companies");
}else
{
//insert
}
}