.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Automatic Insertion Of Record From one table to another by checking the Date.

Posted By: Aamrapali Tamgadge     Posted Date: June 30, 2014    Points:5   Category :VB.Net
Hi .I m having one table with some field and one Distdate field.
I want to check that if TodaysDate=Distdate then Insert in to another Table .this insertion will have to happend automatically if the date match.

IMP:I have To use Task Schedulars


How can i Do this.
Please Help out me.


Responses
Author: ASPEvil             
Posted Date: July 22, 2014     Points: 20   

Hello,

As per your question, I made a database named as:"Aamrapali_Tamgadge" and two tables, named as "Table1" and "Table2".

Table1 contains following fields:-
----------------------------------
name varchar(50)
age varchar(50)
Distdate datetime
----------------------------------

Table2 contains following fields:-
----------------------------------
name varchar(50)
age varchar(50)
Distdate datetime
----------------------------------


Now I took a blank Windows Form(I named this form as: "Form1") and drag and drop a timer control(I named this timer control as: "Timer1") on it. And then I set the "Interval" property of the Timer control to: 1000 which means the code written within the timer control's "Tick" event, will be executed every 1 second, automatically while the application on which this timer is put, is running.


Then I used the following code:-
--------------------------------
Imports System.Data.SqlClient
Imports System.Data
Public Class Form1
Dim con As New SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Aamrapali_Tamgadge;Data Source=(local)")
Dim TodayDate As New Date
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
TodayDate = Now.Date
End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Try
con.Open()
Catch
End Try
Dim cmd As New SqlCommand("insert into Table2 select * from Table1 where Distdate ='" & TodayDate & "'", con)
cmd.ExecuteNonQuery()
con.Close()
End Sub
End Class


--------------------------------

The above code is the Total code I used.


Now to make it a task scheduler which will run automatically when the computer starts, you need to put it either with the "StartUp" folder of the Operating System(Windows) Or with the "Registry" of the Operating System(Windows).
To make it simple, I put the .exe file of this application with the "StartUp" folder of the Operating System(Windows), by the following steps:-
-----------------------------------------
1) First, get the .exe file of this application from the folder of your application where you have saved your application on the Hard Disk of your computer. For example: if you have saved your application with this path: "C:\Aamrapali_Tamgadge\Aamrapali_Tamgadge\bin\Debug" while your application name is: "Aamrapali_Tamgadge", you can get the .exe file there with this same path.

2) With Windows XP, you can get the "StartUp" folder path, as: "C:\Documents and Settings\Aamrapali_Tamgadge\Start Menu\Programs", here: "Aamrapali_Tamgadge" is an user with this computer's Operating System(Windows)

Or for user: "All Users", it will be: "C:\Documents and Settings\All Users\Start Menu\Programs\Startup"

With Windows 7, you can get the "StartUp" folder path, as: "C:\Users\Aamrapali_Tamgadge\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup", here: "Aamrapali_Tamgadge" is an user with this computer's Operating System(Windows)

Or for user: "All Users", it will be: "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup"

3) Now put your application's .exe file with the "StartUp" folder, as mentioned above. Now whenever you will restart your computer, then your application will be continue working until the Windows is ShutDown and from now, your application will start every time Windows starts and will be closed every time Windows closes.
-------------------------------------------------

Hope this will help.


Thanks.

Author: Akhil Raj       [Moderator]      
Posted Date: July 29, 2014     Points: 20   

You can write an sp for this and scheduled in the SQL Server Job.



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend