Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Updating SQ Server record using C#

Posted on 2013-12-03
1
Medium Priority
?
224 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:
Hiran Desai earned 2000 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

670 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