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
Kasuni Abegunawardana
NA
211
124.5k
Incorrect syntax near '2017-12-04'.
Dec 28 2017 9:06 AM
Hi all,
I got an error like this. Why is that? I want to select two data ranges using two text boxes and fill it into grid view?
Incorrect syntax near '2017-12-04'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near '2017-12-04'.
Source Error:
Line 26: SqlDataAdapter sda = new SqlDataAdapter(cmd);
Line 27: DataTable dt = new DataTable();
Line 28: sda.Fill(dt);
Line 29: GridView1.DataSource = dt;
Line 30: GridView1.DataBind();
protected void btn_Search_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("SELECT * FROM InventoryRecords_tb where BuyingDate '" + txtStartDate.Text + "' between '" + txtEndDate.Text + "' ", con);
cmd.Connection = con;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
sda.Dispose();
cmd.Dispose();
con.Close();
}
Reply
Answers (
3
)
Window Fom Code not work in Asp.net
buton onclientclick is not firing after refresh form