TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Albert Ambassy
NA
1
1.5k
Validation for Numeric Value
Oct 10 2011 1:42 PM
Hi,
How can we use Validation to enter Numeric value only in ASP.NET...
Reply
Answers (
2
)
0
Iftikar Hussain
0
12.6k
449.2k
Jul 28 2013 2:29 AM
Here it is
DateTime date = dateTimePicker1.Value.AddDays(-5); // will substract 5 days from selected date
DataTable dt = new DataTable(); //initializing the datatable
using (SqlConnection conn = new SqlConnection(@"Data Source=SQLEXPRESS;Initial Catalog=MyDb;Persist Security Info=True;User ID=MyUserId;Password=MyPassword")) //creating a new sql connection by passing the connection string
{
if (conn.State == ConnectionState.Closed) //checking the connection state
conn.Open(); //opening the connection
string sql= "select *from YourTable where DateColumn>=@Field"; //sql query to select data where DateColumn value is greater than date variable
SqlCommand cmd = new SqlCommand(sql, conn); //creating the sql command
cmd.Parameters.AddWithValue("@Field", date); //adding the parameters to the sql query
SqlDataAdapter dap = new SqlDataAdapter(cmd); //creating data adapter
dap.Fill(dt); //filling the DataTable
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Dispose();
dataGridView1.DataSource = dt; //binding the datatable to gridview
}
Regards,
Iftikar
Accepted Answer
1
Iftikar Hussain
0
12.6k
449.2k
Jul 28 2013 2:16 AM
try like this
DateTime date = dateTimePicker1.Value.AddDays(-5);
DataTable dt = new DataTable();
using (SqlConnection conn = new SqlConnection(@"Data Source=SQLEXPRESS;Initial Catalog=MyDb;Persist Security Info=True;User ID=MyUserId;Password=MyPassword"))
{
if (conn.State == ConnectionState.Closed)
conn.Open();
string sql= "select *from YourTable where DateColumn>=@Field";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@Field", date);
SqlDataAdapter dap = new SqlDataAdapter(cmd);
dap.Fill(dt);
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Dispose();
dataGridView1.DataSource = dt;
}
Regards,
Iftikar
1
Vulpes
0
96k
2.6m
Jul 25 2013 11:12 AM
Try:
string command = "SELECT * FROM Table WHERE DateColumn = '" + dateTimePicker1.Value.AddDays(-5).ToString("dd/MM/yyyy") + "'";
0
ta mu
0
201
82.5k
Jul 28 2013 2:13 AM
this code is selecting records before last five days. how i can select records of last five day what thing i need to change because i cant under stand this code. plz explain with comments
if you can
thank you
0
Iftikar Hussain
0
12.6k
449.2k
Jul 25 2013 11:37 AM
try like this
DateTime date = dateTimePicker1.Value.AddDays(-5);
DataTable dt = new DataTable();
using (SqlConnection conn = new SqlConnection(@"Data Source=SQLEXPRESS;Initial Catalog=MyDb;Persist Security Info=True;User ID=MyUserId;Password=MyPassword"))
{
if (conn.State == ConnectionState.Closed)
conn.Open();
string sql= "select *from YourTable where DateColumn<=@Field";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@Field", date);
SqlDataAdapter dap = new SqlDataAdapter(cmd);
dap.Fill(dt);
if (conn.State == ConnectionState.Open)
conn.Close();
conn.Dispose();
dataGridView1.DataSource = dt;
}
Regards,
Iftikar
0
ta mu
0
201
82.5k
Jul 25 2013 10:52 AM
these are the sql qurries i need c# code
like the crrunt time will be "dateTimePicker1.Value" how to minus 5 day from it and select
records of that days
0
Iftikar Hussain
0
12.6k
449.2k
Jul 24 2013 9:08 AM
Hi,
Try like this
select *FROM YourTable DATEDIFF(dd,GETDATE(),YourDateColumn)<=5
Regards,
Iftikar
0
Riyaz Akhtar
0
1.1k
411.5k
Jul 24 2013 9:04 AM
use your SQL query like below ,
SELECT * FROM TABLENAME WHERE dateColumnname >= convert(varchar(10), DATEADD(DAY, -5, GETDATE()), 120) AND dateColumnname<=GETDATE()
This query will fetch last 5 days records
0
ta mu
0
201
82.5k
Jul 24 2013 8:50 AM
i want to select records from database table and populate them in datagrid view in window form
0
Riyaz Akhtar
0
1.1k
411.5k
Jul 24 2013 7:54 AM
are you storing date in that table ?
Types of Authentication
Passport Authentication