Solved

C# search SQL and edit resulting Row

Posted on 2014-02-19
4
291 Views
Last Modified: 2014-04-07
Guys I'm trying to put together a C# program to checks SQL DB cell called "ExpirationDate"
if the date is greater than Today, update that rows NAME and PHONE and ExpirationDate with new entry.


DB has.

ll NAME ll  Phone ll ExpirationDate ll
  bob          2122        1/1/2010
  adam       3122        2/2/2010
  greg         4122        3/3/2014

code
has 3 text boxes, one of name, phone and expiration date and a button

can someone point me in the right direction
0
Comment
Question by:kentrg11
  • 2
4 Comments
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 39871832
How are you accessing the DB?  LINQ, DataReader, etc...

When you say "update that rows", do you mean update in the database, the text boxes, or both?
0
 
LVL 10

Accepted Solution

by:
Banthor earned 500 total points
ID: 39871900
update Table Set col=newvalue where ExpirationDate > Getdate()
0
 

Author Comment

by:kentrg11
ID: 39873870
hey guys thanks im using LINQ

my code is below. On button click i want it to check "ExpirationDate" cell and if the Date
there is less than TODAY. Replace the row with newly entered information in the Text boxes.
So based on the DB i have below. The text entered in text boxes should replace this row
because the date there is less than Today.

32323      kent            1/1/2010

My Code:
 protected void btnAdd_Click(object sender, EventArgs e)
        {
            DBClassesDataContext db = new DBClassesDataContext();
            tblContacts tc = new tblContacts();
            tc.name = txtName.Text;
            tc.phone = txtPhone.Text;
            tc.ExpirationDate = txtExpirationDate.Text;

            db.tblContacts.InsertOnSubmit(tc);
            db.SubmitChanges();


            Response.Redirect("Default.aspx");
        }

Open in new window


DB looks like this:

Number l  Name  l   ExpirationDate
1322232	Jason	       4/4/2014
32323	kent      	       1/1/2010
323233	bog	               3/2/2014
8018932	stephanie       1/2/2012
NULL	NULL	NULL

Open in new window


Aspx:

Name: txtName.Text
Phone: txtPhone.Text
ExpirationDate:  txtExpirationDate.Text
Button: btnAdd
0
 

Author Comment

by:kentrg11
ID: 39894830
CtrlAltDl im saying update the Database itself.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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