Solved

Updating SQ Server record using C#

Posted on 2013-12-03
1
207 Views
Last Modified: 2013-12-10
I am a newbie to C#,  
My requirement is to manually update a record with data from FormView (VS 2005).

I have the following method where I am getting the value from the fields on the Form.
I am loading them into DtInventory class .  I would like to update the table Inventory with the class values where PartNumberID = the class PartNumberID value.

See the method below:


 protected void Fv_Update(object sender, EventArgs e)
        {

            DtInventory i = new DtInventory();
            i.PartNumberId = Convert.ToInt32(GetValue("PartNumberIDTextBox", ref FormView1));
            i.PartNumber = GetValue("PartNumberTextBox", ref FormView1);
            i.ILSNumber = GetValue("ILSNumberTextBox", ref FormView1);
            i.Revision = GetValue("RevisionTextBox", ref FormView1);
            i.Revision = GetValue("RevisionTextBox", ref FormView1);
            i.Quantity = Convert.ToInt32(GetValue("QuantityTextBox", ref FormView1));
            i.Description = GetValue("DescriptionTextBox", ref FormView1);
            i.MtlDueDate = Convert.ToDateTime(GetValue("MtlDueDateTextBox", ref FormView1));
            i.SerialNumber = GetValue("SerialNumberTextBox", ref FormView1);
            i.MtlReceiptDate = Convert.ToDateTime(GetValue("MtlReceiptDateTextBox", ref FormView1));
            i.PurchaseOrder = GetValue("PurchaseOrderTextBox", ref FormView1);
            i.Supplier = GetValue("SupplieTextBox", ref FormView1);
            i.Location = GetValue("LocationTextBox", ref FormView1);            
            i.Comments = GetValue("CommentsTextBox", ref FormView1);

           string connectionSring = System.Configuration.ConfigurationManager.ConnectionStrings

           ["TrackSparesRepairsConnectionString"].ConnectionString;

          // HOW DO I update table Inventory with the DtInventory class values where
         //  PartNUmberID = i.PartNumberID
        }
0
Comment
Question by:cookiejar
[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
1 Comment
 
LVL 4

Accepted Solution

by:
ItWorked earned 500 total points
ID: 39694639
If you are working with ADO.NET then you can have Dataset ( which is collection of DataTable and allows TWO way communication back-forward with DB which DataTable does not provide)

or you can have a method which saves/updates your Entity into Database. (Assuming you aren't using EF or Linq)

else EF has functionality to do so directly by your DatabaseContext.SaveChange() method.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

751 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