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
Ahmet Taha
NA
381
20.3k
cannot display data between date in gridview c#.
Jun 1 2021 9:21 AM
hello guyz , i need yor help , i cannot display the data between gridview when i filtering it in date , attach here is my source code in this project
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data.SqlClient;
namespace
onlinestudinformation
{
public
partial
class
studentaccountlst : System.Web.UI.Page
{
SqlCommand cmd;
SqlConnection cn;
SqlDataAdapter da;
SqlDataReader dr;
public
void
connectdb()
{
cn =
new
SqlConnection(@
"Data Source=LAPTOP-93441BLD\HUSSIEN;Initial Catalog=studentinfodb;Integrated Security=True"
);
cn.Open();
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
this
.connectdb();
this
.showlist();
}
}
private
void
showlist()
{
this
.connectdb();
cmd =
new
SqlCommand(
"select *from tblOnlineuserregistration "
, cn);
dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
}
protected
void
btnload_Click(
object
sender, EventArgs e)
{
loadadata();
}
void
loadadata()
{
this
.connectdb();
// cmd = new SqlCommand(" SELECT lrn, lastname, firstname, middlename, email, username from tblOnlineuserregistration where registereddate between '" + DateTime.ParseExact(TextBox1.Text, "dd-MM-yyyy", null).ToString("dd/MMM/yyyy") + "' and '" + DateTime.ParseExact(TextBox2.Text, "dd-MM-yyyy", null).ToString("dd/MMM/yyyy") + "'", cn);
cmd =
new
SqlCommand(
" SELECT lrn, lastname, firstname, middlename, email, username,registereddate from tblOnlineuserregistration where registereddate between '"
+ TextBox1.Text +
"' and '"
+ TextBox2.Text +
"'"
, cn);
// cmd = new SqlCommand("Select * from tbl_EmpPayroll where DateFrom between '" + dateTimePicker1.Value.ToString("MM/dd/yyyy") + "' and '" + dateTimePicker2.Value.ToString("MM/dd/yyyy") + "'", conn);
dr = cmd.ExecuteReader();
if
(dr.Read())
{
this
.connectdb();
cmd =
new
SqlCommand(
" SELECT lrn, lastname, firstname, middlename, email, username,registereddate from tblOnlineuserregistration where registereddate between '"
+ DateTime.ParseExact(TextBox1.Text,
"dd/MM/yyyy"
,
null
).ToString(
"dd/MMM/yyyy"
) +
"' and '"
+ DateTime.ParseExact(TextBox2.Text,
"dd/MM/yyyy"
,
null
).ToString(
"dd/MMM/yyyy"
) +
"'"
, cn);
GridView1.DataSource = dr;
GridView1.DataBind();
}
else
{
dr.Close();
// MessageBox.Show("error", "Message....", MessageBoxButtons.OK, MessageBoxIcon.Warning);
ScriptManager.RegisterStartupScript(
this
,
this
.GetType(),
"script"
,
"alert('No record has been found');"
,
true
);
}
}
}
}
Reply
Answers (
2
)
Id value undefined
How to set up azure custom policy with c# api endpoint