471,342 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,342 software developers and data experts.

what is the problem with this?

m.a
Hello,

I am newbie and I am following this tutorial:

http://www.asp.net/learn/data-access...ial-01-cs.aspx

I am using MSVC 2008 and Access database.

I have my own database which is very similar to the database which is used
in this tutorial.

everything seems to be working till I am getting to step 3: Adding
Parameterized Methods to the Data Access Layer.

I cannot create an sql with parameterized data. my sql is as follow:

SELECT ID_Item, Title, [Desc], [image], User_ID
FROM Items
WHERE User_ID = @User_ID

but the system cannot detect that I used a parameter for where clause. it
complains that it can parse code after @ sign.

What is the problem and How can I fix it?

Best regards


Aug 1 '08 #1
1 959
On Aug 1, 12:28*pm, "m.a" <m...@spamoff.comwrote:
Hello,

* I am newbie and I am following this tutorial:

http://www.asp.net/learn/data-access...ial-01-cs.aspx

I am using MSVC 2008 and Access database.

I have my own database which is very similar to the database which is used
in this tutorial.

everything seems to be working till I am getting to step 3: Adding
Parameterized Methods to the Data Access Layer.

I cannot create an sql with parameterized data. my sql is as follow:

SELECT * * ID_Item, Title, [Desc], [image], User_ID
FROM * * * * Items
WHERE * * User_ID = @User_ID

but the system cannot detect that I used a parameter for where clause. it
complains that it can parse code after @ sign.

What is the problem and How can I fix it?

Best regards
You need code to tell it what to replace the parameter with. For
example in C#:
SqlConnection con = GetConnection();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = 500;
cmd.CommandText = "SELECT something FROM somewhere WHERE something =
@yourParam";
cmd.CommandText = cmd.CommandText.Replace("@yourParam", actualValue);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);

Aug 1 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mike Henley | last post: by
8 posts views Thread by Randell D. | last post: by
220 posts views Thread by Brandon J. Van Every | last post: by
699 posts views Thread by mike420 | last post: by
3 posts views Thread by Kenneth McDonald | last post: by
9 posts views Thread by Martin Maney | last post: by
3 posts views Thread by Ron_Adam | last post: by
30 posts views Thread by James Conrad StJohn Foreman | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.