Solved

C# search SQL and edit resulting Row

Posted on 2014-02-19
4
297 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
[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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Copy Database Wizard 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.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

696 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