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
tforrester
NA
7
0
problem with paramters on select statement
Feb 15 2005 9:59 AM
I have just started learning C#, coming from Java. I am trying to do a select statement in the way of a prepared statement which is the kind of thing done in Java all the time. I am not sure if what I am doing is legal, or if it is just the usage I have got wrong: The Error is: Error getting Ticknum: ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near ':'. The code snipits are: dbConn = new OdbcConnection(); dbConn.ConnectionString = connectionString; dbConn.Open(); string query = "select convert(varchar,TICKNUM) TICKNUM from TICKET where convert(datetime,DATEVAL) >= :lowDate and convert(datetime,DATEVAL) <= :hiDate"; IDbCommand command = dbConn.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = query; IDbDataParameter lowDate = command.CreateParameter(); lowDate.ParameterName = ":lowDate"; lowDate.DbType = DbType.DateTime; lowDate.Value = param1; command.Parameters.Add(lowDate); IDbDataParameter hiDate = command.CreateParameter(); hiDate.ParameterName = ":hiDate"; hiDate.DbType = DbType.DateTime; hiDate.Value = param2; command.Parameters.Add(hiDate); command.Prepare(); IDataReader reader = command.ExecuteReader(); Many thanks in advance for your help.
Reply
Answers (
6
)
Accessing SQL table attributes using datatable
about datasets