Accessing two tables from a single mfc application

Hi,
   I need to know how to access two tables using a single mfc(vc++) 
application. I also need to know how to extract data from a table using an 
mfc application using a primary key in a table.It is very important that I 
get answers for these two questions as this is part of my final year college 
project and I have very little time to complete this. Please Help!

Thanks,
Satish.
0
3/13/2005 9:27:02 AM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
428 Views

Similar Articles

[PageSpeed] 51

"Satish Chandrasekar" <yourdisplayname@discussions.microsoft.com> wrote in
message news:A0D7EC0A-18C3-4375-B5A5-AFDB1AB2F577@microsoft.com...
> Hi,
>    I need to know how to access two tables using a single mfc(vc++)
> application. I also need to know how to extract data from a table using an
> mfc application using a primary key in a table.It is very important that I
> get answers for these two questions as this is part of my final year
college
> project and I have very little time to complete this. Please Help!
>
> Thanks,
> Satish.

they didn't teach you much programming i guess.  maybe you should stick
around and take a few more courses.


0
noone1 (387)
3/13/2005 12:23:39 PM
Satish Chandrasekar wrote:

> Hi,
>    I need to know how to access two tables using a single mfc(vc++) 
> application. I also need to know how to extract data from a table using an 
> mfc application using a primary key in a table.It is very important that I 
> get answers for these two questions as this is part of my final year college 
> project and I have very little time to complete this. Please Help!
> 
> Thanks,
> Satish.

More information is needed because there are many database access 
methods available.  What are you using so far?  Is your question "how to 
access" or is the problem "two"?  Tell us what you have now and which 
version of VC you are using.  Do you want to access the tables 
independently or are you asking about doing a join?

If you are using a CRecordset-derived class the answer is probably to 
use two CRecordset-derived classes, one for each table.  In this 
context, to use the primary key see CRecordset::m_strSort.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
3/13/2005 3:43:38 PM
Hello Satish:
Do not get disappoint. With all the other newsgroup msgs. Cheer-up.
You must specify, what database classes you are trying to use. CDAOnnn, or CDatabase
(ODBC), or MS ADO classes. Because all these have a different approach. Create two
different recordset object, make your database object separate. put these recordsets in to
the database. set their sort/ filter options, and use it. I am just giving you some hints.
Good Luck!

"Satish Chandrasekar" <yourdisplayname@discussions.microsoft.com> wrote in message
news:A0D7EC0A-18C3-4375-B5A5-AFDB1AB2F577@microsoft.com...
> Hi,
>    I need to know how to access two tables using a single mfc(vc++)
> application. I also need to know how to extract data from a table using an
> mfc application using a primary key in a table.It is very important that I
> get answers for these two questions as this is part of my final year college
> project and I have very little time to complete this. Please Help!
>
> Thanks,
> Satish.


0
Lord2702 (51)
3/13/2005 8:07:55 PM
Well, fundamentally its all the same.

Create one derived class per Table or View that you wish to use. For 
database centric applications, open one database connection once, use it for 
all recordset opens, make sure all recordsets are closed when finished with 
and close the database last. Avoid opening recordsets without using the 
database connection as that will open an implicit connection and result in 
many potential connections to the DBMS and sooner or later reduce 
performance. Certainly open more than one database connection when needed 
(EG when using report writers, when you have a need for multiple databases 
and so on), and have as many recordsets open of each type as needed when 
needed. The overhead of opening a recordset is minimal but should not be 
inside loops.

Ideally an application should have 1 DB connection only in use - perhaps a 
second if a report writer has been used.

If you wish to do the equivalent of a Seek on a primary key then the method 
does differ. For CDao, see the documentation as the model is almost 
identical in implementation to that which you will find in visual basic with 
the DAO objects there. I don't expect (or hope you are not) using CDao as it 
is old and near obsolete - I don't think it is supported in VS.Net. If you 
are going to learn any database access technology then use either ODBC with 
CRecordset and CDatabase or use the ADO classes. Learn ADO for long term 
forwards compatability. ODBC is fine for medium term applications.

With CRecordset you use the m_strFilter member variable of the CRecordset 
derived class to "seek" or "find" records.

EG

If rsTable1 is a class derived from CRecordset using classwizard has columns 
bound and the Primary Key is called "pkName" and is character then

rsTable1 table(&m_db);    // create an instance using the database 
connection.

table1.m_strFilter.Format("pkName = '%s' "), strSearchFor);
table1.Open()

where m_db is an instance of CDatabase that is already open. If the table 
does have a Primary Key on the field pkName then table1.IsEOF() will be true 
if no record is found, or false if a (one only since it is a Primary Key ==> 
Unique Index ==> only 1 record) record is found:

if (!table1.IsEOF())
{
    // found the 1 record
}
else
{
    // did not find the record
}

You can use any valid criteria in the m_strFilter as per the table design. 
So if you have an index "Index1" that is non unique and it covers the field 
"customerNumber" then

int customerNumber = 552;    // lets look for records for customer 552.

table1.m_strFilter.Format("customerNumber = %i"), customerNumber);
table1.Requery()
if (!table1.IsEOF())
{
    // found one or more records since the index is not unique
}
else
{
    // did not find any records
}

NOTE: if column names include spaces then you will need to enclose them in 
square brackets EG:
table1.m_strFilter.Format("[Customer Number] = %i"), customerNumber);
It is far better to avoid the use of square brackets completely and use only 
Upper / Lower case column names.

If you want the records to be in a set order then use the m_strSort value - 
here you specify the column names with ASC and DESC separated by commas - a 
valid SQL ORDER BY clause is needed. EG

table1.m_strSort = _T("customerName ASC");
table1.m_strFilter.Format("customerNumber = %i"), customerNumber);
table1.Requery()

Use Requery if the table has already been opened (SQL Server, MS Access - 
not all DBMS support Requery) and you wish to either refresh or apply a new 
sort order or a new filter.

ADO is alot different in syntax, but the principles are the same. Just 
remember that SQL indexes and what you search for using m_strFilter are 
important to each other. If a table is large (EG for SQL Server > 100,000 
rows) and you use a column name in a Filter then an index of the right type 
(Uninque, non unique, possibly composite) on the column will help.

HTH
- Tim


"Satish Chandrasekar" <yourdisplayname@discussions.microsoft.com> wrote in 
message news:A0D7EC0A-18C3-4375-B5A5-AFDB1AB2F577@microsoft.com...
> Hi,
>   I need to know how to access two tables using a single mfc(vc++)
> application. I also need to know how to extract data from a table using an
> mfc application using a primary key in a table.It is very important that I
> get answers for these two questions as this is part of my final year 
> college
> project and I have very little time to complete this. Please Help!
>
> Thanks,
> Satish. 


0
Tim
3/14/2005 6:39:55 AM

"Scott McPhillips [MVP]" wrote:

> Satish Chandrasekar wrote:
> 
> > Hi,
> >    I need to know how to access two tables using a single mfc(vc++) 
> > application. I also need to know how to extract data from a table using an 
> > mfc application using a primary key in a table.It is very important that I 
> > get answers for these two questions as this is part of my final year college 
> > project and I have very little time to complete this. Please Help!
> > 
> > Thanks,
> > Satish.
> 
> More information is needed because there are many database access 
> methods available.  What are you using so far?  Is your question "how to 
> access" or is the problem "two"?  Tell us what you have now and which 
> version of VC you are using.  Do you want to access the tables 
> independently or are you asking about doing a join?
> 
> If you are using a CRecordset-derived class the answer is probably to 
> use two CRecordset-derived classes, one for each table.  In this 
> context, to use the primary key see CRecordset::m_strSort.
> 
> -- 

> Scott McPhillips [VC++ MVP]
> 
> 

Hi,
        Firstly,thanks for the reply.I'm working on MS VC++ Version 6.0. I'm 
using ODBC to access the database.I'm able to do all the necessary updations 
if I use a single table (SQL Server 2000-uploaded using the Microsoft 
DTS)with the 'Snapshot' option.It's only when I try to connect two tables 
using  a single VC++ application that  I'm encountering an error.If I try to 
update now a "Recordset cannot be updated as it is read-only" error message 
pops up. Yes, I'm talking about a join operation, in which it is required to 
retrieve values form one table, use a primary key value in that table to 
extract relevant records from the second table, process data and update 
details in the second table.  

     I'm using CRecordset derived class, but how can I use two such classes 
as u suggest (one for each  table). I need your  ideas on this one.

Thanks a lot,
Satish.  
0
3/14/2005 6:41:01 AM

"Tom Alter" wrote:

> Hello Satish:
> Do not get disappoint. With all the other newsgroup msgs. Cheer-up.
> You must specify, what database classes you are trying to use. CDAOnnn, or CDatabase
> (ODBC), or MS ADO classes. Because all these have a different approach. Create two
> different recordset object, make your database object separate. put these recordsets in to
> the database. set their sort/ filter options, and use it. I am just giving you some hints.
> Good Luck!
> 
> "Satish Chandrasekar" <yourdisplayname@discussions.microsoft.com> wrote in message
> news:A0D7EC0A-18C3-4375-B5A5-AFDB1AB2F577@microsoft.com...
> > Hi,
> >    I need to know how to access two tables using a single mfc(vc++)
> > application. I also need to know how to extract data from a table using an
> > mfc application using a primary key in a table.It is very important that I
> > get answers for these two questions as this is part of my final year college
> > project and I have very little time to complete this. Please Help!
> >
> > Thanks,
> > Satish.
> 
> 

Hi,
> Thanks for ur advice I'll try to do this and let u know if  it works for me.

0
3/14/2005 6:43:03 AM
Reply:

Similar Artilces:

Outlook Web Access AutoSignature
I would like to know if it's possible to have autosignature in Outlook Web Access, and if so how to implement it. If anyone can help, it would be greatly apreciated. Thank You. It depends on the version of Exchange - Outlook Web Access is a function of Exchange, not Outlook. Exchange 2003 does this natively, previous versions may have a third party add-in that will allow users to do this. For better information, post in an exchange group such as microsoft.public.exchange.admin. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due t...

Restricting access to note attachments
Hi all, is there a way to restrict access to attachments on notes to specified users. I know we can, using the Security Roles, define who can and can't read/ write the notes fields but we would like our users to be able to view the note, but not open the attachment(s) unless they are the owner of that note (or at least in the business unit, etc.). I know this could be done for Word/ Excel files in Office (Password protection) but are looking for something more encompassing for all attachments inside CRM. Thanks, -- Matt Pring On Oct 21, 3:54=A0pm, Matt Pring <MattPr...@discus...

TWO CRM SERVERS 02-03-06
Is it possible to install two CRM Servers in the same domain using a single Exchange Server? It will work four outbound email, but even with the v3.0 router changes, I do not know if it will work for inbound email. Probably need to check with support on this for sure. -- Matt Parks MVP - Microsoft CRM "Irshard" <Irshard@discussions.microsoft.com> wrote in message news:C18EF5EA-F47C-44CC-9B18-D2799DAF3ED4@microsoft.com... Is it possible to install two CRM Servers in the same domain using a single Exchange Server? yes it is. NOTE: This is already assuming you have two...

Access 2003 and Access 2007 Synchronization
I'm setting up a new business relationship with a company in Portugal. They use Access 2003. I have just bought MS Office Professional 2007 (with Access 2007). Our plan is that they will send, once a month or so, their Access db then we will update and add to that db and then return it after another month or so. There probably won't be a lot of updates on our end so the monthly cycle should work. After they synchronize, they will send a new version of the db and we will start over. My goal is to keep everything as simple as possible partially because I don't know how skillf...

XPath problem with two xmlns
I have got file raport.rld which is an XML file generated by MS Reporting Services. The problem is: in this file are tags from two different namespaces xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefini tion" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" when I'm trying to use XPATH to get <teble> tag it doesn't work. (the result is empty) I've removed All tegs like <rd:TypeName>System.Int32</rd:TypeName> Now all is working fine but what to do when I have tags from two different...

Excel Row to Access Columns
Hi, I have a single row in Excel with a lot of data, what I need to do is move that to a column in Access. I need some way to automate that. I know the easiest way to do that would to just transpose it in excel and then import in access.But I cant do that as I just get that excel file with one row and I need some way to automate the process in Access. thanks m -- mk389 ------------------------------------------------------------------------ mk389's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=15272 View this thread: http://www.excelforum.com/showthread.php?...

Help displaying a random record in a form--Access newbie
Hello, I am new to Access, so if anyone can help me, please assume I know absolutely nothing! I currently have a table with two columns, ID and CHORE. In each row, the ID number corresponds to a chore that I have entered. I would like to create a form with a button and a text field such that when I press the button, a random chore is displayed in the text field (supposed to make chores more "fun" for my son). There is no need to remove this record from future clicks (the same record can come up over and over without any problem for me) Can anyone explain to me (in pai...

How do you make a two page purchase order?
I am using a Purchase order template, and the order needs to be 2-3 pages long. How do I continue the page on to another page and have the ending total be correct? If the sheet formulas are working correctly, then just put page breaks at the spots you want the new pages to begin. -- Gary''s Student - gsnu200713 ...

Printing single record
HELP! I am using the following code under the ComandButton to print the current report from my form: Dim strWhere As String If Me.Dirty Then 'Save any edits. Me.Dirty = False End If If Me.NewRecord Then 'Check there is a record to print MsgBox "Select a record to print" Else strWhere = "[Num] = " & Me.[Num] DoCmd.OpenReport "Check Request", acViewNormal, , strWhere End If However, I keep getting the following error: The expression On Click you entered as the event property setting produced...

Pivot table subtotals 100%
This is what I want: Apples ...

Access
Hi My form takes a few moments to load up as it is fairly substantial SQL statement is there a way to get something to display a graphic or 'loading...' message to appear why it calculate the contents? Steve ...

I can't add 256 color Bitmap! to my Visual C++ Application.
Hi folks I can't add 256 color Bitmap! to my Visual C++ Application Regards David You can use LoadImage to load it. -- Ajay Kalra [MVP - VC++] ajaykalra@yahoo.com "David" <anonymous@discussions.microsoft.com> wrote in message news:56C2D61B-7556-4484-A317-D16B53D255B9@microsoft.com... > Hi folks, > > I can't add 256 color Bitmap! to my Visual C++ Application. > > Regards, > David ...

access mail on WEB
Is there a way i can check emails from exchanger server 5.5 from an internet browser. I have Exchange 5.5 in win NT 4.0. Thanks! Yes - install OWA (Outlook Web Access) and open up the needed ports in your firewall (80 for http; better to use SSL and port 443 instead). disk0nek wrote: > Is there a way i can check emails from exchanger server > 5.5 from an internet browser. > > I have Exchange 5.5 in win NT 4.0. > > Thanks! ...

access or mount mirrored hard disks
Hi, is it possible to access a mirrored harddrive? or mount the mirrored volume by using api or mfc commands? Thank you in advance Wimpi ...

How do i set up two series on a scatter plot?
I need to set up two series on my scatter plot so that I can do two trendlines to find my stoichiometric point from all data gathered in my chemistry lab class. Make the chart as usual with one of the series. Copy the range containing X and Y values for the next series, select the chart, and use Paste Special from the Edit menu to add a New Series, Categories in First Column. Now do a trendline for each series. - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services Tutorials and Custom Solutions http://PeltierTech.com/ _______ yellastang wrote: > I need to set up...

how to add two business cards to Outlook 2003 signature card
I have two businesses, one a dealer and the other a manufaturer's rep. Is there a way to add another business card graphic (I use a scanner to scan my business cards to put into signature)? No. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Outlook 2007: http://www.slipstick.com/outlook/ol2007/ Outlook Tips by email: dailytips-subscribe-request@lists.outlooktips.net Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com Subscribe t...

Unique distinct count in pivot table?
I have the following table with fields "Name", "State", and "price": Name State price Mary OH 14.94 Mary OH 15.01 Joe WA 12.17 Joe WA 18.95 I create a pivot table putting State in the row area and Count of Name in the data area. I get the following results: State OH 2 WA 2 This is telling me the number of occurrences of a name in the table in a given state. What I want it to tell me is the number of different names in a state. Is there an elegant way to do this in a pivot table? Much thanks for any help. A pivot table won't calculate a uni...

Access Database In Great Plains
I was wondering if anyone knew how to have the databases that are stored in access transfered over to great plains. I'm current running version 8.0 any help would be greatful. thanks Search Customer Source for integration Manager. MS Access databases can be used as a data source. Vincev "jake" wrote: > I was wondering if anyone knew how to have the databases that are > stored in access transfered over to great plains. I'm current running > version 8.0 any help would be greatful. thanks > > Hi Jake, Is this something you need to do regularly or is it ...

CRM v4 Accessibility Improvements
Hi all: Does anyone know if any improvements have been med to CRM v4 in the area of accessibility for handicapped users? One of my customers has a user who is blind and they need to make the software accessible to him. Thanks in advance for any and all help. John. Hi John, We have added following Accessibility features in CRM 4.0 : 1) High Contrast Mode (Tools --> Options --> General Tab --> Enable high contrast settings) 2) All the Form input elements have <LABEL FOR> to aid in screen readers. 3) All the Images have a ALT tag (for non text elements) etc. Thanks! Ma...

Upsizing Access to SQL Server 2000
Hello, I am new to SQL Server. I am trying to use the Database upsizing wizard to upsize a Access 2000 database into SQL Server 2000. They are both on the same machine (running Win 03 Server). I cannot connect to the SQL Server. Error as below: Connection failed: SQLState: '01000' SQL Server Error: 14 [Microsoft][ODBC SQL Server Driver][Shared Memory] ConnectionOpen(Invalid Instance()). SQLState: '08001' SQL Server Error: 14 [Microsoft][ODBC SQL Server Driver][Shared Memory]Invalid connection. ...

Outlook Web Access #19
We have have OWA at my work and I would like to configure Outlook 2003 to synchronize with my desktop at work, is this possible Thanks B ...

Missing values from a pivot table field
I am creating a pivot table from an access database containing 896426 records. The issue I am running into is that on one of the fields the pivot table is only pulling in one of two values, but the access table does contain the second value. When I click on the arrow associated with that field it does not contain the second value either. Is there somewhere else in the settings this value could have been lost? Perhaps try Drag the field off the table Refresh the table Drag the field back on. With pivot tables you need to let us know which XL version you have. pivot ta...

Have a user account accessible to multiple users
I have an issue where there is a user account that has multiple alias emails.(reservations@domain.com, info@domain.com, CustomerService@domain.com) I have an exchange 2003 server. My issue is that i need to have muliple users access these emails so they are never missed. What is the best way to accomplish this? I was thinking a public folder. But i want to know the best way to do this? On Sat, 12 Jun 2010 21:37:04 -0500, "Dan V" <dvalenti54athotmail.com> wrote: >I have an issue where there is a user account that has multiple alias >emails.(reservati...

Going offline without write access to registry
I suggest that POS doesn't go offline if it can't write into registry, displaying a message box instead telling that it couldn't access the registry. What happens if the POS machine goes offline without having access to edit the registry? This typically happen when the user is a normal user (not a power user) 1. The POS application will try to connect to the server main database within the pre-configured ‘Connect Timeout’ in the RMS Administrator (Typically 15 seconds) 2. The application will then try to connect to the pre-defined offline database (which is usually stored loc...

Access 2000 problem if opened with Access 2007
Dear all, I'm running Access 2000 MDE in Access 2007. I find several header-details form (such as invoice transaction), the details form is displayed as white box without any record displayed. Is there any solution for this matter ? Thanks. Chlaris. you need to move to Access Data Projects if you want a reliable, predictable environment "Chlaris" <chlarrissa_nospam@yahoo.com> wrote in message news:ON0rS1NsHHA.3884@TK2MSFTNGP04.phx.gbl... > Dear all, > > I'm running Access 2000 MDE in Access 2007. I find several header-details > form (such as inv...