Click here to Skip to main content
13,348,874 members (76,828 online)
Rate this:
Please Sign up or sign in to vote.
See more:
hi everyone
have a good time

i know that how can i connect to a "mdf" file in visual c#, but i can't connect to that with visual c++.
can anyone help me?
i used "CDatabase" class but didn't get result.
thanks a lot
Posted 18-Dec-12 4:39am
Updated 21-Dec-12 2:05am
Richard MacCutchan 21-Dec-12 7:40am
If you want some help then you need to provide more details about your problem. Do not expect people to guess what you mean by expressions such as "but didn't get result.".
Jochen Arndt 21-Dec-12 9:06am
Some general tips:

If you want to answer to a comment, use the 'Reply' link on the right side of that comment (like I have done here). Then the poster of the first comment gets an email notification and might answer. Otherwise, he will see your post only when reviewing your question what probably would not happen with a two day old question.

You should not post code blocks in comments. It's really hard to read. If the code clarifies your question (like in this case), add it to your question using the green 'Improve question' link (don't forget to format it well there by marking it as code section). The side effect of editing is that your question will be pushed back on top of the questions.

If you edit your question don't just add the code block. Add also some text where you have problems and what you have tried (e.g. error messages, tried tracing with the debugger and saw that this variable does not contain the expected result or so).

All these tips will increase the chance to get an answer.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

All right my friend
this is code that i used:

CDatabase database;
	CString SqlString;
	CString ssn,firstname;
	CString sDriver = _T("SQL Server");
	CString sDsn, sMc;
	CString sFile = _T("G:\\shop.mdf");

	// You must change above path if it's different
	int iRec = 0; 	
		// Open the database
		// Allocate the recordset
		CRecordset recset(&database);
		// Build the SQL statement
		SqlString =  _T("select * from dbo.items");
		// Execute the query
		// Reset List control if there is any data
		while( !recset.IsEOF() )
	catch(CDBException* e)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180111.1 | Last Updated 22 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100