I wrote this SQL statement and tested it with SQL Server Management Studio. However I'm not sure how to do this with C#. I have tried with SqlCommand.ExecuteNonQuery();
and it didn't work. What am I missing?
C#:
string query = "SELECT ISNULL(CAST(CustId AS INT), 0) AS AccountNumber,
ISNULL(CAST(CompanyName AS NVARCHAR),'') AS Company,
ISNULL(CAST(CustName AS NVARCHAR),'') AS FirstName,
ISNULL(CAST(LastName AS NVARCHAR),'') AS LastName,
ISNULL(CAST(Email AS NVARCHAR),'') AS EmailAddress,
ISNULL(CAST(ROUND(CustLoyaltyPoints,0),0) AS NVARCHAR) AS CustomText1
INTO db2.dbo.CustomerTemp
FROM db1.dbo.Customer;";
connection = new SqlConnection(strConnect); //connection already defined above
SqlCommand command = new SqlCommand(query, connection);
command.ExecuteNonQuery();