|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
C# / ADO.NET QuestonsI have been moving from Delphi/C++ Win32 Database Development (ADO) to C#.Net /ADO.NET the language is not the problem ADO.NET is however kicking my butt. I finally get the true power and purpose of a Dataset, wow, that was a light bulb Not easy when you are still thinking ADO RecordSets almost got the basics down, , NOT! From what i have read so far, this is a hurdle for lots of coders. I have developed a tiny little DB program against SQL Server to test my skills and all works fine, then I try the most mundane and simple of tasks and realize I have no clue what I'm doing. The Simple Problem (Made Small): I have a DataGrid and a Button I click the button and I want it to update the current record (Currently Selected in the Grid) Lets say, update the Field/Colum Named "Price" to 19.95 Old School Delphi MyTable.Edit; MyTable.FieldByName("PRICE").Value := 19.95 MyTable.Post; // ^This would have edited the CURRENT Record. The Question How do I Access the "Current" Active Record in a DataGrid Programmatically and Update one of the fields Programmatically My Guess is something Like MyDataSet.Tables[0].SOMETHING // IM LOST HERE By Asking this question I hope to: 1) learn How To Access DataSet's Table Members BY Column Name and update the value Programmatically. 2) Find out whether or not ADO.NET even knows what the current active Record is in my DataSet I am a good coder, i just need the light bulb to go on- I need that moment to happen. My Head is Stuck In something like this: MyDataSet.Tables[0].Edit; MyDataSet.Tables[0].Field("PRICE") = 19.95 MyDataSet.Tables[0].Post; Light bulb just went off.. or ON as it were! Thank you all anyway! Any
pointers for my .Net ventures are always welcome by email! Hello, DaBrain.
Well known problem when moving to C#/ADO.NET Can advice you to read couple of good articles: http://www.codeproject.com/cs/database/DatabaseAcessWithAdoNet1.asp http://www.codeproject.com/cs/database/relationaladonet.asp As for current record in DataGrid and how to find it in DataTable see informaton concerning BindingManagerBase. for example: //--- private BindingManagerBase bindingManagerBase; bindingManagerBase = dataGrid1.BindingContext[DataSet1.Table[0]]; //--- so you can invoke active record of your dataGrid1 from bindingManagerBase as bindingManagerBase.Position and access current record of Table[0] as //--- DataSet1.Table[0].DefaultView[bindingManagerBase.Position]["YourFieldName"] = 19; //---- But if you use Oracle DB I can offer a good solution which is very close to Delphi/ADO. Best Regards, Michael Milonov http://www.snotratech.com Show quote > I can use some help here. > > I have been moving from Delphi/C++ Win32 Database Development (ADO) to > C#.Net /ADO.NET the language is not the problem ADO.NET is however > kicking my butt. |
|||||||||||||||||||||||