what is the problem with this?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • m.a

    #1

    what is the problem with this?

    Hello,

    I am newbie and I am following this tutorial:



    Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.


    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






  • rhaazy

    #2
    Re: what is the problem with this?

    On Aug 1, 12:28 pm, "m.a" <m...@spamoff.c omwrote:
    Hello,
    >
      I am newbie and I am following this tutorial:
    >
    Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.

    >
    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.CreateComma nd();
    cmd.CommandType = CommandType.Tex t;
    cmd.CommandTime out = 500;
    cmd.CommandText = "SELECT something FROM somewhere WHERE something =
    @yourParam";
    cmd.CommandText = cmd.CommandText .Replace("@your Param", actualValue);
    SqlDataAdapter adapter = new SqlDataAdapter( cmd);
    DataSet ds = new DataSet();
    adapter.Fill(ds );

    Comment

    Working...