Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Open Points: 125 Time: 05:01 - May 05, 2008  

mike2098

Trying to add date to table sql and run query to email results

I am ussing SQL Express and VB 2005 on Vista x64

I am trying to create a simple table with

userID double
email Varchar
date (datetime)

so when a new record is added it is timestamped in the database I have tried ussing [Date] but it either resets to Date or [Date]]] neither insert a date into the database. I need to use the date time for a query to be run that will email all the email addresses from the last 24 hrs

so I need help with the date and also is there a way of of using a timer to query the database and send and email

thanks

Categories

Answer Discussion
Tutorials

 

rcastagna

Date:: Sep 25, 2008

Time:: 09:39

Mike,

Using SQL Management Studio Express, open the database and table you're working with. If you will highlight the "date" column and look at the properties (usually displayed below the table designer) you will see a property for "Default Value".

Enter "getDate()" into that default value column and it will automatically set the current system timestamp into the database.

Alternatively, you could add a parameter to your insert statement that would add the date in as well.

SqlConnection cn = new SqlConnection("YourConnectionString");
SqlCommand cmd = new SqlCommand("InsertRecord", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@UserID", SqlDbType.Decimal).Value = userID;
cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = email;
cmd.Parameters.Add("@Date", SqlDbType.DateTime).Value = DateTime.Now;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();

The way to automatically email folks could be done with a Windows Service or perhaps a scheduled job. For the scheduled job you'll need to consider Windows Script Host or whatever is the current replacement. I prefer to use the service approach.

Let me know if there's anything else I can do to help you on the way.

Take care,
Ric

admin

Date:: Mar 24, 2009

Time:: 09:49

The question looks to be abandoned by the user who asked it. If no action is taken within 2 days, a Quomon Moderator will consider closing the question and distributing the points.

The Quomon Team

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Tutorials cannot be submitted until the Answer Discussion is complete.

Submit answers in the Answer Discussion area

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10354

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es