Solved

primary key on DBF to get C# app to work

Posted on 2007-04-06
2
1,155 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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