Solved

Updating SQ Server record using C#

Posted on 2013-12-03
1
200 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
1 Comment
 
LVL 4

Accepted Solution

by:
ItWorked earned 500 total points
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

763 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

7 Experts available now in Live!

Get 1:1 Help Now