Solved

primary key on DBF to get C# app to work

Posted on 2007-04-06
2
1,140 Views
Last Modified: 2008-01-09
I am tring to update a dbf file with C# in Visual Studio 2003.  I am getting an error on update and delete:
not supported against a SelectCommand that does not return any key column information

In researching this, I have read that it is because my dbf table does not have a primary key.  How do I set up a primary key on a dbf?  I have Visual FoxPro 6.0, but am not fluent in it AT ALL.  I usually work with Access, which is very different than FoxPro.  

I have included code below, just in case it helps:

            private void DBFtoMDB(string mdbName, string dbfName)
            {    
                      tempSyncSltCmd.CommandText = "SELECT * FROM " + dbfName;
                  tempSyncSltCmd.Connection = tempSyncConn;
                  tempSyncAdapt.SelectCommand = tempSyncSltCmd;
                  tempCB = new System.Data.OleDb.OleDbCommandBuilder(tempSyncAdapt);

                  DataSet dsDBF = new DataSet();
                  tempSyncAdapt.TableMappings.Add("Table", dbfName);
                  tempSyncAdapt.Fill(dsDBF, dbfName);

            dsDBF.Tables[0].Rows[2].Delete();


                 tempSyncAdapt.Update(dsDBF, dbfName);
            
            } //End of DBFtoMDB



 
0
Comment
Question by:absolutesolutions
2 Comments
 
LVL 33

Expert Comment

by:CarlWarner
ID: 18868594
You should be somewhat familiar with some SQL stuff and use of the ALTER TABLE command.

ALTER TABLE - SQL Command
http://msdn.microsoft.com/library/en-us/dv_foxhelp9/html/3c5a454a-67ec-48a8-8290-18dd0e8a97ea.asp?frame=true
0
 
LVL 8

Accepted Solution

by:
suhashegde earned 250 total points
ID: 18871674
It is possible to update and delete w/o the primary key because Foxpro has a physical Record number.
i.e. the records are numbered 1 to .... as based on row.

SO you will have to manually create a deletecommand and a updatecommand
ex : (Dont use Order by Cluse as it might give unexpeted results) TRY this code and modify to suite your needs

 private void DBFtoMDB(string mdbName, string dbfName)
            {    
                  int recno = 2 ;//base 1 in foxpro not 0 as in C# so second record will be marked as deleted
                      tempSyncSltCmd.CommandText = "SELECT * FROM " + dbfName;
                  tempSyncSltCmd.Connection = tempSyncConn;
                  tempSyncAdapt.SelectCommand = tempSyncSltCmd;
                 // tempCB = new System.Data.OleDb.OleDbCommandBuilder(tempSyncAdapt);
                  DataSet dsDBF = new DataSet();
                  tempSyncAdapt.TableMappings.Add("Table", dbfName);
                  tempSyncAdapt.Fill(dsDBF, dbfName);
                  tempSyncAdapt.DeleteComand.CommandText = @"Delete from "+dbfName+" where Recno() = "+ recno;
// now send the execute the command

                  tempSyncAdapt.Delete()
                 tempSyncAdapt.Update(dsDBF, dbfName);
           
            } //End of DBFtoMDB
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
crm development 2 37
Pass through dll 2 37
Paging GridView 7 34
Why don't I see this table in EDMX file? 2 20
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now