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
Israel
631
1.3k
217.3k
Incorrect syntxt near '?'
May 18 2018 6:53 AM
Hi,
I worte these codes and its works very well when I use MSAccess Database. Curiosly doesnt works usin sql database. When I make filter its gives this message: Incorrect syntax near '?'
Please any help:
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
//cmd.CommandText = "select * from taxas_habitacionais where (data between ? and ?) and name = ?";
cmd.CommandText =
"select * from livro1 where (data between ? and ?)"
;
var param1 =
new
SqlParameter(
"@StartDate"
, SqlDbType.Date);
var param2 =
new
SqlParameter(
"@EndDate"
, SqlDbType.Date);
//var param3 = new OleDbParameter("@name", OleDbType.VarChar); // use actual type of 'name' here
param1.Value = dtInicialLivro1.Value.Date;
param2.Value = dtFinalLivro1.Value.Date;
//param3.Value = txtConsFaltasPorNomes.Text; // or whatever
if
(dtFinalLivro1.Value <= dtInicialLivro1.Value)
{
cmd.Parameters.Add(param1);
cmd.Parameters.Add(param2);
}
else
{
cmd.Parameters.Add(param2);
cmd.Parameters.Add(param1);
}
//cmd.Parameters.Add(param3);
cmd.ExecuteNonQuery();
DataTable dt =
new
DataTable();
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
da.Fill(dt);
conn.Close();
dgvLivro1.DataSource = dt;
Reply
Answers (
3
)
Select, Insert, Update and Delete data with DataGrideView
getting started with UWP