Reputation: 3
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);
}
Upvotes: 0
Views: 180
Reputation: 12629
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 + "'";
Upvotes: 0