Solved

primary key on DBF to get C# app to work

Posted on 2007-04-06
2
1,144 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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