0

I get an error. How can I avoid this? Does anyone have any ideas? Note: The more I'm new :)

queryStringId.Text = Request.QueryString["ID"].ToString();
        SqlCommand komut = new SqlCommand();
        baglanti.Open();
        komut.Connection = baglanti;
        komut.CommandText = "SELECT * FROM SatilikDaire where ID=" + queryStringId.Text;
        komut.ExecuteNonQuery();
        SqlDataReader dr = komut.ExecuteReader();

1 Answers1

1

Just set a breakpoint and inspect which element is null. Either Request is null or QueryString["ID"] returns null or queryStringId is null.

Then once you have identified the element ensure it is not null anymore. If you don't know how to do that please go back to the basics of programming.

ViRuSTriNiTy
  • 4,581
  • 1
  • 27
  • 52
  • Yes, you are right. I have learned a bit more basics. Thank you for your response and your suggestions – Enver köseler Jul 15 '16 at 08:35
  • I made the following methods. How wrong I do not know how true `if (Request.QueryString["ID"] == null) { Label1.Text = ("kayıt yok"); } else { queryStringId.Text = Request.QueryString["ID"].ToString(); ............ } else { veriYok.Text = "Veri Yok :("; }` – Enver köseler Jul 15 '16 at 08:56
  • @Enverköseler Loos ok but it is better to store the value of `Request.QueryString["ID"]` in a variable (e.g. `var id = Request.QueryString["ID"]`) and use this variable later on. This avoids retrieving the *ID* twice and is easier to debug as you can e.g. set conditions on the variable. Also please accept the answer if the issue is solved. – ViRuSTriNiTy Jul 15 '16 at 09:19
  • I am grateful to you for your interest and relevance. Thank I gave your vote – Enver köseler Jul 15 '16 at 09:42