Solved

primary key on DBF to get C# app to work

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 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

11 Experts available now in Live!

Get 1:1 Help Now