Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Able to connect and display .dbf data but not update
Message
De
25/02/2007 09:58:11
 
 
À
25/02/2007 04:53:41
Dave Nantais
Light speed database solutions
Ontario, Canada
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01198383
Message ID:
01198622
Vues:
8
>these are great examples Bonnie;
>thank you for this great help.


You're welcome, Dave. =0)

>I gather that for updating current records i use the UPDATE - SQL command in Foxpro.
>Because the UPDATE - SQL command in Foxpro has a WHERE clause to limit which records get updated... the only way I can insure only 1 record is updated is by defining in hte WHERE clause the correct value for the primary key.


Of course. I only showed the code for the INSERT and left it to the reader to figure out the code for the DELETE and UPDATE.

Also, I guess I should mention that parameters are treated different for VFP than for the SQL example I posted. Either I forgot or I didn't have time to mention it in my first post ... VFP paramters are specified with a "?" and are positional rather than named. So, in this example:
         sc.CommandText = "Insert into bob (xyz, abc) VALUES ( ?, ? )";
         sc.Parameters.Clear();
         sc.Parameters.Add("xyz", Row["xyz"]);
         sc.Parameters.Add("abc", Row["abc"]);
... the first "?" corresponds to the first parameter, "xyz" in this case, the second "?" is the second parameter, etc.

~~Bonnie


>
>I'd like to examine one of your solutions in detail to insure I understand the concepts.
>
>public void UpdateMyData(DataSet ds)
>{
>	// I wouldn't actually hard-code the connection string here, it should be in your config settings
>	string TestConnection = "server=(local);database=MyDataBase;uid=sa;pwd=MyPassword";
>
>SqlCommand sc = new SqlCommand();
>sc.Connection = new SqlConnection(TestConnection);
>sc.Connection.Open();
>foreach (DataRow Row in ds.Tables[0].Rows)
>   {
>   switch (Row.RowState)
>      {
>         case DataRowState.Added :
>
>         sc.CommandText = "Insert into bob (xyz, abc) VALUES ( @xyz, @abc )";
>         // the item in quotes is basically a foxpro INSERT - SQL command
>
>         sc.Parameters.Clear();
>
>
>
>         sc.Parameters.Add("@xyz", Row["xyz"]);
>         sc.Parameters.Add("@abc", Row["abc"]);
>         // the 2 lines above replace @xyz, @abc in the INSERT command with the actual
>         // contents of the row that is in focus in current iteration of the foreach
>
>         sc.ExecuteNonQuery();
>         // here the changes are committed to the table
>         break;
>				
>			// Do the same for DataRowState Deleted and Modified
>			case DataRowState.Deleted :
>				break;
>			case DataRowState.Modified :
>				break;
>		}
>	}
>	sc.Connection.Close();
>}
>
>I gather that for updating current records i use the UPDATE - SQL command in Foxpro.
>Because the UPDATE - SQL command in Foxpro has a WHERE clause to limit which records get updated... the only way I can insure only 1 record is updated is by defining in hte WHERE clause the correct value for the primary key.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform