Solved

C# search SQL and edit resulting Row

Posted on 2014-02-19
4
289 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

17 Experts available now in Live!

Get 1:1 Help Now