ren fud fud_%date:~4,2%-%date:~7,2%-%date:~10,4%_%time:~0,2%%time:~3,2%_%time:~6,5%.jpg
Wednesday, 16 March 2016
Tuesday, 15 March 2016
Check file exists using c#
if (File.Exists(filePath)) {
byte[] data = File.ReadAllBytes(filePath);
string fileName = Path.GetFileName(filePath);
const string query = "INSERT INTO Files (FileName, Data, Path) VALUES (@FileName, @Data, @Path)";
using (var connection = new SqlConnection(connectionString))
using (var command = new SqlCommand(query, connection)) {
command.Parameters.AddWithValue("@FileName", fileName);
command.Parameters.AddWithValue("@Data", data);
command.Parameters.AddWithValue("@Path", filePath);
connection.Open();
command.ExecuteNonQuery();
}
}
http://www.codeproject.com/Tips/849516/How-to-Search-for-an-Excel-File-in-a-Folder-using
http://www.codeproject.com/Articles/368530/Dynamic-Excel-file-loading-with-SSIS
https://www.youtube.com/watch?v=_B83CPqX-N4
https://www.youtube.com/watch?v=Ui4vera72Ng
Monday, 14 March 2016
Task.Delay Example in c#
private void button4_Click(object sender, EventArgs e)
{
if (textBox6.Text != "" && textBox7.Text != "" && textBox8.Text != "" && textBox9.Text != "" )
{
// 11:00:00
var DailyTime = "" + textBox8.Text + ":" + textBox7.Text + ":" + textBox6.Text + "";
var timeParts = DailyTime.Split(new char[1] { ':' });
var dateNow = DateTime.Now; // current time
var date = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day,
int.Parse(timeParts[0]), int.Parse(timeParts[1]), int.Parse(timeParts[2])); // user input time
TimeSpan ts;
if (date > dateNow)
ts = date - dateNow;
else
{
// date = date.AddDays(1);
date = date.AddHours(12);
ts = date - dateNow;
if (date == dateNow)
// ts = date - dateNow;
ts = dateNow - date;
}
string msg = textBox9.Text;
//waits certan time and run the code
Task.Delay(ts).ContinueWith((x) => SomeMethod(msg));
Console.Read();
MessageBox.Show("Reminder added succesfully !!");
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
}
else
{
MessageBox.Show("All Fields Are Mandatory !!");
}
}
static void SomeMethod(string reminderMsg)
{
// MessageBox.Show("" + reminderMsg + "" + "@:" + DateTime.Now.ToString());
// MessageBox.Show(new Form() { TopMost = true }, "" + reminderMsg + "" + "@:" + DateTime.Now.ToString());
TopMostMessageBox.Show("" + reminderMsg + "" + " Reminder set at :"+ DateTime.Now.TimeOfDay.ToString()+"", "Reminder !!!", MessageBoxButtons.OK);
}
{
if (textBox6.Text != "" && textBox7.Text != "" && textBox8.Text != "" && textBox9.Text != "" )
{
// 11:00:00
var DailyTime = "" + textBox8.Text + ":" + textBox7.Text + ":" + textBox6.Text + "";
var timeParts = DailyTime.Split(new char[1] { ':' });
var dateNow = DateTime.Now; // current time
var date = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day,
int.Parse(timeParts[0]), int.Parse(timeParts[1]), int.Parse(timeParts[2])); // user input time
TimeSpan ts;
if (date > dateNow)
ts = date - dateNow;
else
{
// date = date.AddDays(1);
date = date.AddHours(12);
ts = date - dateNow;
if (date == dateNow)
// ts = date - dateNow;
ts = dateNow - date;
}
string msg = textBox9.Text;
//waits certan time and run the code
Task.Delay(ts).ContinueWith((x) => SomeMethod(msg));
Console.Read();
MessageBox.Show("Reminder added succesfully !!");
textBox6.Text = "";
textBox7.Text = "";
textBox8.Text = "";
textBox9.Text = "";
}
else
{
MessageBox.Show("All Fields Are Mandatory !!");
}
}
static void SomeMethod(string reminderMsg)
{
// MessageBox.Show("" + reminderMsg + "" + "@:" + DateTime.Now.ToString());
// MessageBox.Show(new Form() { TopMost = true }, "" + reminderMsg + "" + "@:" + DateTime.Now.ToString());
TopMostMessageBox.Show("" + reminderMsg + "" + " Reminder set at :"+ DateTime.Now.TimeOfDay.ToString()+"", "Reminder !!!", MessageBoxButtons.OK);
}
Monday, 7 March 2016
BCP CSV FILE TO SQL SERVER TABLE
NOTEPAD FORMAT : SAVE AS .fmt
11.0
3
1 SQLCHAR 0 10 "," 1 ID SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 20 "," 2 NAME SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 30 "\r\n" 3 ADDR SQL_Latin1_General_CP1_CI_AS
PROC :
CREATE TABLE TEMPSVK(ID INT,NAME VARCHAR(20),ADDR VARCHAR(20))
exec master..xp_cmdshell 'bcp "test.dbo.TEMPSVK" in "D:\excel\Check.csv" -T -F1 -f "D:\excel\test.fmt" '
select @@SERVERNAME
select * from TEMPSVK
truncate table TEMPSVK
exec master..xp_cmdshell 'bcp "test.dbo.TEMPSVK" in "D:\excel\Check_1.xls" -T -F1 -f "D:\excel\test.fmt" '
SAMPLE EXCEL IN CSV FILE FORMAT :
ID NAME ADDR
100 AAA CHENNAI
101 BBB CHENNAI
102 CCC CHENNAI
11.0
3
1 SQLCHAR 0 10 "," 1 ID SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 20 "," 2 NAME SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 30 "\r\n" 3 ADDR SQL_Latin1_General_CP1_CI_AS
PROC :
CREATE TABLE TEMPSVK(ID INT,NAME VARCHAR(20),ADDR VARCHAR(20))
exec master..xp_cmdshell 'bcp "test.dbo.TEMPSVK" in "D:\excel\Check.csv" -T -F1 -f "D:\excel\test.fmt" '
select @@SERVERNAME
select * from TEMPSVK
truncate table TEMPSVK
exec master..xp_cmdshell 'bcp "test.dbo.TEMPSVK" in "D:\excel\Check_1.xls" -T -F1 -f "D:\excel\test.fmt" '
SAMPLE EXCEL IN CSV FILE FORMAT :
ID NAME ADDR
100 AAA CHENNAI
101 BBB CHENNAI
102 CCC CHENNAI
Subscribe to:
Posts (Atom)