Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
Incorrect syntax near '2017-12-04'.
Kasuni Abegunawardana
Dec 28 2017 9:06 AM
156
Reply
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();
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
Window Fom Code not work in Asp.net
buton onclientclick is not firing after refresh form