.NETGURU
Query Problems
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.

Post a new message to this list...

Don Kim
Hi,

I'm trying to port the IGo Portal on the gotdotnet site from vb.net to c#.
I'm having problems with the following:

public DataSet GetAnnouncements(int moduleId) {

// Create Instance of Connection and Command Object
SqlConnection myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlDataAdapter myCommand = new SqlDataAdapter("SELECT ItemID,
CreatedByUser, CreatedDate, Title, MoreLink, MobileMoreLink, ExpireDate,
Description FROM Portal_Announcements WHERE ModuleID = ? AND ExpireDate >
?", myConnection);

// Mark the Command
myCommand.SelectCommand.CommandType = CommandType.Text;

// Add Parameters
SqlParameter parameterModuleId = new SqlParameter("@ModuleID",
SqlDbType.Int, 4);
parameterModuleId.Value = moduleId;
myCommand.SelectCommand.Parameters.Add(parameterModuleId);

// Add Parameters
SqlParameter parameterExpireDate = new SqlParameter("@ExpireDate",
SqlDbType.DateTime);
parameterExpireDate.Value = DateTime.Now;
myCommand.SelectCommand.Parameters.Add(parameterExpireDate);

// Create and Fill the DataSet
DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet);

// Return the DataSet
return myDataSet;
}

I get this error: System.Data.SqlClient.SqlException: Line 1: Incorrect
syntax near '?'.

Does anyone have any ideas? Thanks.

- Don Kim

Reply to this message...
 
    
Chris R. Timmons
"Don Kim" <Click here to reveal e-mail address> wrote in
news:lXj%c.12648$Click here to reveal e-mail address:

[Original message clipped]

Don,

Parameters in SQL commands used in the System.Data.SqlClient
namespace are referenced by name, not position. Therefore, you need
to replace the "?" placeholders in the SELECT statement with the
parameter name:

SqlDataAdapter myCommand = new SqlDataAdapter(
@"SELECT ItemID, CreatedByUser, CreatedDate, Title, MoreLink,
MobileMoreLink, ExpireDate, Description FROM
Portal_Announcements WHERE ModuleID = @ModuleID AND
ExpireDate > @ExpireDate", myConnection);

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Reply to this message...
 
    
Don Kim
[Original message clipped]

Absolutely correct. Forgot that oledb provider is different from sql.
Thanks.

- Don Kim

Reply to this message...
 
 
System.Configuration.ConfigurationSettings
System.Data.CommandType
System.Data.DataSet
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlDataAdapter
System.Data.SqlClient.SqlException
System.Data.SqlClient.SqlParameter
System.Data.SqlDbType
System.DateTime




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification