0
Answer

Pass Data from sql Database to DataTable

Kevin Yu

Kevin Yu

18y
2k
1
Hi All,

I am using VC++ 2005 Express and SQL Server express. The database MyDB has shown in the Data Sources panel after applying "add new data source" steps. In the MYDB, there is a table called "MyTable", which is also shown in Data Sources panel. How do I transfer data from MyTable to a DataTable ("dtTable")? I tried following codes but it didn't work.

SqlDataAdapter^ sqlAdapter;
DataTable^ dtTable;
sqlAdapter = gcnew sqlDataAdapter("select * from MyTable", "MyDB");
dtTable = gcnew DataTable("dtTable");
sqlAdapter->Fill(dtTable);

Any suggestions? Thanks in advance.

Kevin