Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

This question already has an answer here:

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();
share|improve this question

marked as duplicate by Nasreddine, fubo, Phylogenesis, user3185569, Tim Schmelter asp.net Jul 15 at 8:27

This question was marked as an exact duplicate of an existing question.

    
Perhaps Request.QueryString["ID"] is null – Timothy Ghanem Jul 15 at 8:20
    
Please learn to use prepared statements. This is wide open to SQL injection. – Phylogenesis Jul 15 at 8:32

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.

share|improve this answer
    
Yes, you are right. I have learned a bit more basics. Thank you for your response and your suggestions – Enver köseler Jul 15 at 8: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 at 8: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 at 9:19
    
I am grateful to you for your interest and relevance. Thank I gave your vote – Enver köseler Jul 15 at 9:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.