AllExperts > C# 
Search      
C#
Volunteer
Answers to thousands of questions
 Home · More C# Questions · Answer Library  · Encyclopedia ·
More C# Answers
Question Library

Ask a question about C#
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Hosnieh [Sara]
Expertise
Questions which I can answers: 1- Programming (C#.net, Vb.net, javascript, HTML) more Web applications 2- CSS 3-Databases (Ms SQL server -all versions) 4-OS (workstation and servers (windows)) 5- MS office 6- General problems in computer software I cannot answer other kinds of questions which I did not mention here.

Experience
my CV: http://iran-americamarket.com/Contact.aspx I have more than 8 years Experience in IT field. my core skills are : • Asp.net Developer (Portal, Dynamic websites ,e-commercial websites) • Visual studio.net 2003,2005,2008 (VB.net , C#.net , AJAX.net) • O.O programming (n-tier Architecture) • Database (SQL server 2000-2005, Oracle9i, Ms Access) , TSQL, Stored procedures, Triggers • IIS 5-6 , SSL (Installation and configuration SSL) , Network(TCP/IP ,Active directory , DHCP, … ), Windows 2000-2003 Server Configuration and administration • UML (usecase diagram, class diagram) , Microsoft Project • Graphics Design( Photoshop , Flash ) • JavaScript , CSS, DHTML, XML • Hardware (physical installation, configuration , and driver installation) • Ms Office all versions (Ms word, Ms Access, Ms Excel, Ms Outlook , Ms FrontPage, and etc) • OS (Windows –Linux) and VMware • Network Monitoring (Solarwinds) • Computer Teacher, English Teacher • MATLAB (simulations and computation projects)

Organizations
-

Publications
Translation Experience English to Farsi • Use brain scan to predict when people will buy products . May 2008 (Published in AI Magazine) – Medicine , AI • Totally tubular motors _Tomorrow automation technology : March 2008 (Published in AI Magazine) – AI , Mechanic, Industry • Improving PLC compatibility and function flexibility: March 2008 (Published in AI Magazine) – AI , Robotics , Industry • Make packaging lines more flexible: January 2008 (Published in AI Magazine) – AI , Robotics , Industry • Personal CNC : December 2007 (Published in AI Magazine) – AI , Medical , Industry • Multipurpose optical tools Characterize as MEMS: December 2007 (Published in AI Magazine)- optical physics • Managing Innovation: November 2007 (Published in AI Magazine) – IT Management • Calculating the total value of ownership (TVO):October 2007 (Published in San-ate Hooshmand Magazine) -IT and Economics

Education/Credentials
I am currently student and doing my Master in Computer Network Engineering

Awards and Honors
- Poster about new methods of management in Organization( Entrepreneurship ) - 2007

Past/Present Clients
-

 
   

You are here:  Experts > Computing/Technology > Microsoft .NET > C# > how to use Dataset object and objectDataSource to edit data

C# - how to use Dataset object and objectDataSource to edit data


Expert: Hosnieh [Sara] - 10/19/2009

Question
QUESTION: Dear Hosnieh
Hi
I 'm new to ASP.NET and C#.
I have some table which are joined together.
for example: contractsDetails and Companies that are joined to each other on companyID.
I created a Dataset Item under my business layer and created a table adapter based on a select query on it to get all the information of a contract and the related company together.
it was for Fill and Get methods.
i made an update query which updates only contract details, not company details.
in my page, i have a grid View which lists the information of contracts and the company name.and the selection property of the grid view is actived.
there is a form view that shows the details of the row in which is selected.
I attached it to an ObjectDataSource which is related to my Dataset. I set the select, Update &... methods.
the process of showing data works properly, but NoT editing & deleteing data &... .
i got this error:
the ObjectDataSource cannot find a non-generic "update" method which have parameters: contractID, submitDate, submitNum & ....(all the paramethers which i used in my update query)
but i have this method in my dataset item and also i have this
parameters in my ObjectDataSource
Now is there any solution?
do you want to attach my project or my code?
by the way, i am Iranian too, can I continue this discussion in Persian?
thanks.


ANSWER: Salam,
yes you can write in Persian,
Do you set parameters to your objectdatasource, also if you have relational tables do you set their relation for update and delete command I mean when you delete something,or update something affect on both table or you don't want this happen?
if you don't know how to set parameters  you can find an example in the following links on MSDN
http://msdn.microsoft.com/en-us/library/57hkzhy5.aspx
if this is not what you need , let me know more about your problem.
Regards,


---------- FOLLOW-UP ----------

QUESTION: salam,
matlabi ke link karde boodi ro khoondam.
dar oon mesalha oomade code zade, man az tarighe bakhshe design parameters ro set kardam,
tasviri ke too in linke(http://zahralizadeh.persiangig.com/other/question-pic/tables.bmp)
table ha ro neshoon mide, farz kon alan ba company va contract kar mikonam,
ke rooye (contract.peymankar)&(company.ID) be ham join shodan.
baraye edit ham mikham faghat ettelaate contract update she.
in link(http://zahralizadeh.persiangig.com/other/question-pic/dataset.bmp) ham tasviri az item Datasetame
+++++++++
commande update ine:
UPDATE    contract2
SET              location = @location, karfarma = @karfarma, karfarma_name = @karfarma_name, karfarma_post = @karfarma_post, peymankar = @peymankar,
                     peymankar_name = @peymankar_name, peymankar_post = @peymankar_post, subject = @subject, howlong = @howlong, start_date = @start_date,
                     fin_date = @fin_date, cost = @cost, submit_date = @submit_date, submit_NO = @submitNO, serial = @serial
FROM         contract2 INNER JOIN
                     companies ON contract2.peymankar = companies.id
WHERE     (contract2.ID = @Original_ID)
++++++++
code objectDataSource man ine:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="Original_{0}" SelectMethod="GetData"
           TypeName="DataSet1TableAdapters.contractTableAdapter" UpdateMethod="UpdateQuery">
           <UpdateParameters>
               <asp:ControlParameter ControlID="FormView1" Name="location" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="karfarma" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="karfarma_name" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="karfarma_post" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="peymankar" PropertyName="SelectedValue"
                   Type="Int32" />
               <asp:ControlParameter ControlID="FormView1" Name="peymankar_name" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="peymankar_post" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="subject" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="howlong" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="start_date" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="fin_date" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="cost" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="submit_date" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="submitNO" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="serial" PropertyName="SelectedValue"
                   Type="String" />
               <asp:ControlParameter ControlID="FormView1" Name="Original_ID" PropertyName="SelectedValue"
                   Type="Int32" />
           </UpdateParameters>
           <SelectParameters>
               <asp:ControlParameter ControlID="GridView1" Name="ID" PropertyName="SelectedValue"
                   Type="Int32" />
           </SelectParameters>
       </asp:ObjectDataSource>
+++++++++++
code form view ham ine:
<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" DataSourceID="ObjectDataSource1">
           <EditItemTemplate>
               ID:
               <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />
               karfarma:
               <asp:TextBox ID="karfarmaTextBox" runat="server" Text='<%# Bind("karfarma") %>'></asp:TextBox><br />
               karfarma_name:
               <asp:TextBox ID="karfarma_nameTextBox" runat="server" Text='<%# Bind("karfarma_name") %>'></asp:TextBox><br />
               karfarma_post:
               <asp:TextBox ID="karfarma_postTextBox" runat="server" Text='<%# Bind("karfarma_post") %>'></asp:TextBox><br />
               peymankar:
               <asp:TextBox ID="peymankarTextBox" runat="server" Text='<%# Bind("peymankar") %>'></asp:TextBox><br />
               peymankar_name:
               <asp:TextBox ID="peymankar_nameTextBox" runat="server" Text='<%# Bind("peymankar_name") %>'></asp:TextBox><br />
               peymankar_post:
               <asp:TextBox ID="peymankar_postTextBox" runat="server" Text='<%# Bind("peymankar_post") %>'></asp:TextBox><br />
               subject:
               <asp:TextBox ID="subjectTextBox" runat="server" Text='<%# Bind("subject") %>'></asp:TextBox><br />
               location:
               <asp:TextBox ID="locationTextBox" runat="server" Text='<%# Bind("location") %>'></asp:TextBox><br />
               howlong:
               <asp:TextBox ID="howlongTextBox" runat="server" Text='<%# Bind("howlong") %>'></asp:TextBox><br />
               start_date:
               <asp:TextBox ID="start_dateTextBox" runat="server" Text='<%# Bind("start_date") %>'></asp:TextBox><br />
               fin_date:
               <asp:TextBox ID="fin_dateTextBox" runat="server" Text='<%# Bind("fin_date") %>'></asp:TextBox><br />
               cost:
               <asp:TextBox ID="costTextBox" runat="server" Text='<%# Bind("cost") %>'></asp:TextBox><br />
               submit_date:
               <asp:TextBox ID="submit_dateTextBox" runat="server" Text='<%# Bind("submit_date") %>'></asp:TextBox><br />
               submit_NO:
               <asp:TextBox ID="submit_NOTextBox" runat="server" Text='<%# Bind("submit_NO") %>'></asp:TextBox><br />
               serial:
               <asp:TextBox ID="serialTextBox" runat="server" Text='<%# Bind("serial") %>'></asp:TextBox><br />
               :
               <br />
               <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                   Text="Update"></asp:LinkButton>
               <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                   Text="Cancel"></asp:LinkButton>
           </EditItemTemplate>
           <InsertItemTemplate>
               karfarma:
               <asp:TextBox ID="karfarmaTextBox" runat="server" Text='<%# Bind("karfarma") %>'>
               </asp:TextBox><br />
               karfarma_name:
               <asp:TextBox ID="karfarma_nameTextBox" runat="server" Text='<%# Bind("karfarma_name") %>'>
               </asp:TextBox><br />
               karfarma_post:
               <asp:TextBox ID="karfarma_postTextBox" runat="server" Text='<%# Bind("karfarma_post") %>'>
               </asp:TextBox><br />
               peymankar:
               <asp:TextBox ID="peymankarTextBox" runat="server" Text='<%# Bind("peymankar") %>'>
               </asp:TextBox><br />
               peymankar_name:
               <asp:TextBox ID="peymankar_nameTextBox" runat="server" Text='<%# Bind("peymankar_name") %>'>
               </asp:TextBox><br />
               peymankar_post:
               <asp:TextBox ID="peymankar_postTextBox" runat="server" Text='<%# Bind("peymankar_post") %>'>
               </asp:TextBox><br />
               subject:
               <asp:TextBox ID="subjectTextBox" runat="server" Text='<%# Bind("subject") %>'>
               </asp:TextBox><br />
               location:
               <asp:TextBox ID="locationTextBox" runat="server" Text='<%# Bind("location") %>'>
               </asp:TextBox><br />
               howlong:
               <asp:TextBox ID="howlongTextBox" runat="server" Text='<%# Bind("howlong") %>'>
               </asp:TextBox><br />
               start_date:
               <asp:TextBox ID="start_dateTextBox" runat="server" Text='<%# Bind("start_date") %>'>
               </asp:TextBox><br />
               fin_date:
               <asp:TextBox ID="fin_dateTextBox" runat="server" Text='<%# Bind("fin_date") %>'>
               </asp:TextBox><br />
               cost:
               <asp:TextBox ID="costTextBox" runat="server" Text='<%# Bind("cost") %>'>
               </asp:TextBox><br />
               submit_date:
               <asp:TextBox ID="submit_dateTextBox" runat="server" Text='<%# Bind("submit_date") %>'>
               </asp:TextBox><br />
               submit_NO:
               <asp:TextBox ID="submit_NOTextBox" runat="server" Text='<%# Bind("submit_NO") %>'>
               </asp:TextBox><br />
               serial:
               <asp:TextBox ID="serialTextBox" runat="server" Text='<%# Bind("serial") %>'>
               </asp:TextBox><br />
               name:
               <asp:TextBox ID="nameTextBox" runat="server" Text='<%# Bind("name") %>'>
               </asp:TextBox><br />
               <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                   Text="Insert">
               </asp:LinkButton>
               <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                   Text="Cancel">
               </asp:LinkButton>
           </InsertItemTemplate>
           <ItemTemplate>
               ID:
               <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />
               karfarma:
               <asp:Label ID="karfarmaLabel" runat="server" Text='<%# Bind("karfarma") %>'></asp:Label><br />
               karfarma_name:
               <asp:Label ID="karfarma_nameLabel" runat="server" Text='<%# Bind("karfarma_name") %>'></asp:Label><br />
               karfarma_post:
               <asp:Label ID="karfarma_postLabel" runat="server" Text='<%# Bind("karfarma_post") %>'></asp:Label><br />
               peymankar:
               <asp:Label ID="peymankarLabel" runat="server" Text='<%# Bind("peymankar") %>'></asp:Label><br />
               peymankar_name:
               <asp:Label ID="peymankar_nameLabel" runat="server" Text='<%# Bind("peymankar_name") %>'></asp:Label><br />
               peymankar_post:
               <asp:Label ID="peymankar_postLabel" runat="server" Text='<%# Bind("peymankar_post") %>'></asp:Label><br />
               subject:
               <asp:Label ID="subjectLabel" runat="server" Text='<%# Bind("subject") %>'></asp:Label><br />
               location:
               <asp:Label ID="locationLabel" runat="server" Text='<%# Bind("location") %>'></asp:Label><br />
               howlong:
               <asp:Label ID="howlongLabel" runat="server" Text='<%# Bind("howlong") %>'></asp:Label><br />
               start_date:
               <asp:Label ID="start_dateLabel" runat="server" Text='<%# Bind("start_date") %>'></asp:Label><br />
               fin_date:
               <asp:Label ID="fin_dateLabel" runat="server" Text='<%# Bind("fin_date") %>'></asp:Label><br />
               cost:
               <asp:Label ID="costLabel" runat="server" Text='<%# Bind("cost") %>'></asp:Label><br />
               submit_date:
               <asp:Label ID="submit_dateLabel" runat="server" Text='<%# Bind("submit_date") %>'></asp:Label><br />
               submit_NO:
               <asp:Label ID="submit_NOLabel" runat="server" Text='<%# Bind("submit_NO") %>'></asp:Label><br />
               serial:
               <asp:Label ID="serialLabel" runat="server" Text='<%# Bind("serial") %>'></asp:Label><br />
               name:
               <asp:Label ID="nameLabel" runat="server" Text='<%# Bind("name") %>'></asp:Label><br />
               <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                   Text="Edit"></asp:LinkButton>
           </ItemTemplate>
       </asp:FormView>
+++++++++
koja ro ja endakhtam?  

Answer
salam,
masaleyeh aval inke agar shoma darid yek table ro update mikonid dige chera az inner join... estefade kardid niazi be on nadarid.
faghat chizi ke toyeh db barayeh in do ta table set mikoni va khodetam mikhay be cheshme khodet bebini ine ke boro toyeh ghesmate diagram/right click/new database diagram  bad right click royeh safhe in dota table ro add kon , bad az id yeki be on yeki drag kon (primary key va foreign key ro dar nazar begir)bad ghesmate "insert/update specification"  delete rule : cascade   update rule : cascade
be in soorat har update va deleti royeh joft table tasir mizare.agar halate defaultesh bashe update anjam bedi error behet mide hamintor delete chon vabaste be on table hast.
chize digeii ke nemidoonam set kardi ine ke shoma goftid
    <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit"
                  Text="Edit"></asp:LinkButton>
khob ama toyeh khode form viewer barayeh command "Edit chizi tarif nakardid hamintor commnad delete faghat goftid vojood dare vali esm barash nazashtid.
<asp:FormView ID="FormView1" runat="server"  OnItemDeleted="name of function in your code" OnItemUpdated="" >
in link ro negah kon

http://www.aspnettutorials.com/tutorials/database/formviewdata-csharp.aspx
ta zamani ke chizi barayeh delete va update set nashe formviewer command delete va update shoma ro nemishnase harchnad ke barayeh button gozashte bashi.
baz moshkeli bood ersal kon.

Add to this Answer   Ask a Question


 
User Agreement | Privacy Policy | Kids' Privacy Policy | Help
Copyright  © 2008 About, Inc. AllExperts, AllExperts.com, and About.com are registered trademarks of About, Inc. All rights reserved.