0

Please help me to find error on my code

public ActionResult Details(string id) { String connectionString = ConfigurationManager.ConnectionStrings["SAPB1"].ConnectionString; SqlConnection conn = new SqlConnection(connectionString); String sql = "Select a.[CardCode] As CCODE,a.[CardName] As Name from ocrd a where a.CardCode = " + id; SqlCommand cmd = new SqlCommand(sql, conn);

        BPModel BP = new BPModel();
        using (conn)
        {
            conn.Open();
            
            if (string.IsNullOrEmpty(id))
            {
                

            }

            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                BP.CCODE = rdr["CCODE"].ToString();
                BP.Name = rdr["Name"].ToString();

            }




        }

        return View(BP);
    }

1 Answer 1

0

You need to wrap your id values inside single quote ('). Try like below.

String sql = "Select a.[CardCode] As CCODE,a.[CardName] As Name from ocrd a where a.CardCode = '" + id + "'";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.