I have a C# code that executes the SQL query. The input of the SQL query comes from a result of a stored procedure. The stored procedure returns a table 6 columns and 25,000 rows. I want to use this stored procedure result as an input to the SQL query. I am storing the stored procedure result in a DataSet. It looks like it's not the correct way to add DataSet results in the query. I need help here experts
Here is what I am doing.
public static void ExecuteSQLQueryTest(string qryName, Boolean nestedQry, string spName)
{
DataTable dtLocalResult = new DataTable();
DataTable dtAzurelResult = new DataTable();
DataTable dt = new DataTable();
DataTable dt1 = new DataTable();
List<string> lstring = new List<string>();
aadSQLConnection.Open();
//Connection to CPDashboard DB
var cpdbconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["CATSQL"].ConnectionString);
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = cpdbconnection;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = spName;
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
}
string qryName = "Update A SET A.Environment = B.SC_MD_Environment, A.OSImage = B.SC_APMD_OSImage FROM" + dt + " A"
+ "INNER JOIN[CLOUD].cloudsql.caa.aa_AT_S B ON A.ServerName = B.SC_APMD_MachineName";
using (SqlCommand cmd = new SqlCommand())
{
cmd.Connection = aadSQLConnection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = qryName;
using (SqlDataAdapter daa = new SqlDataAdapter(cmd))
{
daa.Fill(dt1);
}
}
}