jeudi 7 juillet 2016

Sql Query giving no result in asp.net

I am trying to check if a person has a past crime history or not by looking up his NIC number in criminal database. but the query is not fetching any data although there is no exception and relevant data is present in the database but still Data Reader is empty Please see the following code:

    SqlCommand cmd5 = new SqlCommand("select * from criminal where NIC ="+nic, conn);
    string nic = "null";
    foreach (var person in allInvolved)
                {
                    conn.Open();
                    nic = person.NIC;
                    dr3 = cmd5.ExecuteReader();


                        if (dr3.HasRows)
                        { do something}
                        else if (!dr3.HasRows)
                         { do something else}
                }

Variable NIC has the correct value in it, I checked it while debugging. I don't know where am I going wrong. If you need any other info regarding the code please ask. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire