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
1082 Views

Similar Articles

[PageSpeed] 14

"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:

How do I select a range of cells in an Excel table using the mouse
When I use the mouse to select a range of cells in an Excel table (left-button-click-and-hold, drag mouse mouse over desired cell range), when I release the mouse ALL the data in the top row of the selected range is COPIED to the remaining rows in the selected range... How do I prevent this, or what is wrong w/my selection technique. -- John C. Lethco Be more careful with your initial click. I'm thinking that you got the edge of the cell, not the cell itself. jlethco_texas wrote: > > When I use the mouse to select a range of cells in an Excel table > (left-...

visual basic
Hi, I trying to retrieve values from a table to calculate the 14days average value of a stock closing price. However, i encounter some problem as stated beside the code as follows: Function DaysAvgs() 'Calculate the average value of a given value. Dim db As DAO.Database Dim rst As DAO.Recordset Dim varBookmark As Variant Dim numAve, numDaysAvg As Double Dim intA, intB, lngCount As Integer Set db = CurrentDb 'Open Table Set rst = db.OpenRecordset("SGX Individual Historical", dbOpenTable) rst.MoveFirst Do While Not rst.EOF intA = 1 intB = 0 varBookmark = rst.Bookmark n...

How to "watch cursor" over other application?
How to receive window object under mouse cursor in my app, when cursor is over another windows application? I think about function like "Watch Cursor" implemented in inspect32.exe from MSAA SDK Tools: http://www.microsoft.com/downloads/details.aspx?familyid=3755582a-a707-460a-bf21-1373316e13f0&displaylang=en When user moves cursor, inspect32.exe checks frequently what object is under the cursor, and shows information about it (Options->Watch Cursor must be set). Maybe you know where is available source code for inspect32.exe ? Maybe WindowFromPoint() and/or ChildWindo...

Troubleshooting "Rules"
Hi, I am trying to cope with spam by creating rules from messages in my Junk folder. I am hilighting the message and then selecting either the "From" option or the "Subject" option. All seems to go well up to that point. However . . . After clicking OK and then selecting "run this rule in this folder now", the only message that is deleted is the one that I am using to create the rule, instead of going through the whole Junk folder, as expected. Another problem that I am having is with the Search funciton. Again in my failaing efforts to cope with over...

Browsing on a single Subnet
My problem, and hopefully an easy problem for you guys with more knowledge on the subject, is that sometimes I can see the list of computers/servers on the network (one single subnet network) thru My Network Places->Entire Network->Microsoft Windows Networks and sometimes I can't. I have 2 DCs (windows 2003 Ent. Ed. w/ SP1), one member server (2003 ent. ed. w/ SP1 as well) and 10 to 12 workstations, all XP Pro w/ Sp2 with the firewall feature manually disabled on all of them. On my DC1, I have forced it to always be the Domain Master Browser by doing the registry hack. This D...

Pivot Table
Dear All I built a pivot table by getting the data from an external datasource. It works fin all the time but now I want to add a parameter to the source so that everytime when I placed the parameter and click refresh. The pivot table will give the result according to the parameter. Do you have any idea on it? Thank you very much!! Regards, Hi, You could put the Parameter field into the Page area and then pick the parameter there. However, if you code the data retrevial you can input a parameter into the SQL statement. So if the first one doesn't work record a macro that cre...

Pivot table -Show Q3 and Q4 with non-filtered Total
Hi guys, Need help with the question detailed below. In my Pivot Table: Field "Qty" is xlDataField. Field "Quarter" is xlColumnField. The report shows the quantities for each quarter, like: Q1 Q2 Q3 Q4 Total 2 5 4 5 16 I need to show only Q3 and Q4, but live the "Total" with the whole quantity, like: Q3 Q4 Total 4 5 16 How can I achieve that? Thanks in advance, Aldo. ...

Tooltips working in MFC app, but not from DLL
I have a class which is derived from CWnd. It creates a couple of buttons, which have tooltips. Tooltips is implemented by calling EnableToolTips() and by handling the generated messages: ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify) ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify) The code works fine. But, I have taken my code and placed it into a DLL. The DLL has one entry point. There I create my class, including the buttons. When my code is in a dll, tooltips no longer works. OnToolTipNotify never gets called. In stepping through the code, ...

How to implement the outer join in ACCESS for more than 2 tables?
I have three tables (Employees, Outsourced and Projects). Projects table include project_id, project_name, emp_id as foreign key to Employees.id and Outsourced _id as foreign key to Outsourced.id. I need a query to show the project name, Employee_name, Outsourced name. Kindly, to help me to generate the SQL Statement. The SQL you can use Select Projects.[project name], Employees.[Employee_name] , Outsourced.[Outsourced name] From (Projects Inner Join Employees On Projects.emp_id = Employees.emp_id ) Inner Join Outsourced On Projects.Outsourced _id = Outsourced.Outsourced _id But yo...

Field changed from Single to Double issue..
I have an Access 2000 DB (I think it's 2000, it's whatever comes with Visual Studio 6.0).. Simply put, I have a field that is of type "Single" that contains the value 0.3. When I modify that field and make it "Double", access automatically converts the values, as it should, but returns 0.300001192 in the field.. I understand that there can be precision issues sometimes in comparisons and such, but is this NORMAL for Access to do as well? Is there any simple work around or patch? I suppose I can write an SQL statement to take care of this, but that isn...

Adjust an Excel table with the width of a Word page
Hol=E0 has todos los Excel users!! Here is my small problem (way of speaking, because for me it is an enormous problem, but for you, it is undoubtedly nothing.): Under Excel, I have a macro that creates several tables on several sheets (1 table per sheet). This macro selects and copies each table into a page in Word. The problem is that the number of columns is variable : at the time of copying, the table doesn't not fit the width of the Word page. That's why I'm seeking a way to do the following things : 1) calculate the number of columns of the xls table 2) find the width of ...

Pivot Tables
Is there a way to use pivot tables in Excel to accomplish the same result as an MS-Access process to "join" two tables on matching fields? For example, I have one range of data that contains employee time card information that includes a costing code for each time entry. I have a separate data range that contains, for each costing code, one or more records containing percentages that are used to allocate labor to specific business units. The desired result is a table or data range that contains all of the records from the time card range and all matching record...

Server Error 403 Forbidden: Access is denied
Running Windows XP SP3 attempting Windows Update. Attempted to use the information in the below thread, however, I am not having any success. I have attempted reinstalling the Update agent, restarting computer and still receiving the same error. Part of the tread was a little too technical and I was getting lost. "MMurphy" wrote: > Running Windows XP SP3 attempting Windows Update. > Attempted to use the information in the below thread, however, I am not > having any success. I have attempted reinstalling the Update agent, > restarting computer and ...

Pivot Table - Data Field
Hi All, I trying to create a custom data field within a Pivot Table that calculates the remaining sum, in a sense the opposite of the "Running Total In" option fo the "Show data as" parameter in the Field Settings bar. So for example if I have the follow data items in a column: 1, 4, 7, 3, 7 Column Total being 22 Then the running total would be 1, 5, 12, 15, 22 And the remaining sum would be 21, 17, 10, 18, 0 I cannot find any way of doing this. Since I cannot use GETPIVOTDATA within a Pivot Table's calculated field, I cannot make a reference to the Column Total. C...

autofit whole table?
I'm sick of adjusting cell heights individually! Is there a way to make an Excel table autofit contents to a cell automatically throughout the document? I want the widths to stay stable, but the heights of cells to adjust to the text. I want the whole document to work this way and not have to go to each individual cell and adjust them. TIA. ~~~~~~~~~~~~~~~~~~~ Delete the obvious to reply to me personally. ~~~~~~~~~~~~~~~~~~~ Lobo You cannot adjust cell heights individually. Perhaps you mean "row heights"? Select your range of rows and Format>Rows>Autofit. G...

same x-axis with two sources of data
I am having trouble using different columns of data on the same x-axis. When the a new series is added it swaps to one or the other x-axis column rather than each having its own sepatate data. Any suggestions? Jeremy wrote: > I am having trouble using different columns of data on the > same x-axis. When the a new series is added it swaps to > one or the other x-axis column rather than each having its > own sepatate data. Any suggestions? Sorry, but I do not have any idea what you mean. Can you try again? Dave dvt at psu dot edu ...

Convert Access 2003 to 2000
I have two very similar Access databases in the 2003 format. I must convert each to the 2000 format. One database converted without any difficulty. The other one gives me an error message: "The report name 'DirDataCopy' you entered in either the property sheet or macro is misspelled or refers to a report the doesn't exist". From what I find in a couple of forums, I am not the only one who has received the message. Can someone please point me to some kind of a solution? Or, at least give me some kind of idea as what to look for in my database? Using Access 2...

Re: Displaying Electrical Connections on Two Wires
Hi all, Just wondered if someone may be able to explain to me - in layman's terms - how to show electrical connections between two-wires on an electrical schematic drawing in Visio. I am currently using Visio 2002. Say for instance if I draw a three-phase diagram, and from the first phase, I connect a single-phase switch and lamp, how do I show the black-dot connection between the two wires? Many thanks, Regards, Matt On Thu, 1 May 2008 05:23:00 -0700, tips6 <tips6@discussions.microsoft.com> wrote: >Hi all, > >Just wondered if someone may be able to explain to me...

Sending a mail from Access to Outlook
Hello! I have a form in Access that sends mails through an Office Outlook profile. DoCmd.SendObject , , , "myMail@hotmail.com", , , "subject", "Text", False 'So the email is sent without being displayed This works perfectly, but Outlook displays an alert message saying: "A program is trying to automatically send email on your behalf. Do you want to allow this? If this unexpected, it may be a virus and should choose No." [Yes] [No] How can we avoid this message? so I can send my emails on a row. Thanks for any suggestion See htt...

access 03 converted file size
I am migrating from Access 97 to Access 2003. I converted an access 97 file to Access 03 db. the size of the Access 97 file was 7,778KB where as the converted access 03 file size was 2,736KB. When I compared with a db comparision tool for the differences b/n the two db's, it showed a difference in table structure of memo field and unicode compression. My question is: Is the reduced size in the Access 03 file due to unicode compression or due to some other reason. Please some one clarify. What is the reason for the difference in the size of the converted db's. How do I make su...

Permission denied when access javascript
Hi, I'm a newbie on MS CRM. I tried to customize crm with external aspx file and IFRAME. I found a problem that when I call javascript (in external aspx file) in onsave event then error pop up. "There was an error with this field's customized event." "Field: crmForm" "Event: onSave" "Error: Permission denied" I guess permission denied may came from IIS configure but I don't know how to do. Can anyone help me on this problem ? In the properties of the iframe you need to enable cross-site scripting. HTH, -- Jeffry van de Vuurst CWR Mo...

Can Access 2007 be Run as Admistrator
Using Vista: have launched an .adp project created at another site on another computer, using the SQL Server at that site. Now, from home, I want to change the data source to the local SQL Server database on my PC here at home. So, I entered the local SQL Server name in the Data Link Properties dialog box, and pressed the Test Connection button. Getting an error message: "Test connection failed because of an error in initializing provider. Login failed for user 'SLINDEED\(My name). If I cannot run as Administrator or change the server name, Catch 22? Thanks, Dean S &q...

Invalid Argument Access 2003
I get an invalid argument when I open my database. The database is the front end for a split database. I was working with some large imports. The file has swelled to over 2 GB. It should be around 50MB. I have tried to repair the DB from inside access and using the command prompt. I get a corruption error telling me to back up the DB and repair/compact. I have tried to rebuild the DB by importing to a blank DB. However, I get the invalid argument and corruption errors. When I double click on a module, Access tells me it doesn't exist. I have 40K lines of code and lots of forms and...

Application to load driver
If anyone can tell me how to create an user mode application that can load the driver in kernel space(identical to those given with sioctl.sys sample in WDK)? What type of driver? If it is a legacy driver take a look at src\general\event\exe\install.c in the WDK. If it is a PnP driver then you need to look at src\install\devcon and take the pieces that insall the driver from there. Don Burn (MVP, Windows DKD) Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr > -----Original Message----- > From: P...

Vista and Access 2003
I am running an access 2003 application as a Client Server, with the front end on users PCs and the _be on the server. Until now all pcs have been using WindowsXP. A new HP laptop has been purchased with Vista. I had difficulty initially running the application and relinking the _fe to the _be on the server -which is normally a straight forward operation with an XP machine but was unstable with the Vista machine. Eventually after a few tries I got the link working and the application worked fine for an hour or so but then just fell over. I have done the same thing a number of times but the res...