Can't SqlCommand - Help.

Hi all,

I am using VS C++ 2005 and SQL Server 2005 to build a simple application which will work with a database.

I can write the code to open the database which all goes well, but as soon as I write in a 'SqlCommand' and execute it I get an error message telling me that the 'Connection' property hasn't been 'initialised'.

The code I have writted is as follows:

#include "stdafx.h"

using namespace System;

using namespace System::Data;

using namespace System::Data::Sql;

using namespace System::Data::SqlClient;

int main()

{

SqlConnection conn("Data Source=gps028;Initial Catalog=master;Integrated Security=True");

SqlCommand cmd("CREATE DATABASE dbTest");

conn.Open();

cmd.ExecuteNonQuery();

return 0;

}

Where am I going wrong with the code

Pete



Answer this question

Can't SqlCommand - Help.