-5

I have this comamand and that error, in data i have zip code 79000 and table name site

   private void Crt_clck_Click(object sender, EventArgs e)
    {

        {
            con.Open();
            SqlCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "SELECT CMC, [Site Name], [Phone Number], Zip_Code FROM site Where Zip_Code'" + Zipcode.Text + "'";
            cmd.ExecuteNonQuery();
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            con.Close();
        }

can you help me with this

Mighty Badaboom
  • 6,067
  • 5
  • 34
  • 51
Joe
  • 9
  • 5

1 Answers1

5

Change your sql statement to

cmd.CommandText = "SELECT CMC, [Site Name], [Phone Number], Zip_Code FROM site Where Zip_Code = '" + Zipcode.Text + "'";

You are missing the = which is needed for the syntax to be correct.

But you should think about using parameter instead to avoid SQL Injection.

Why do we always prefer using parameters in SQL statements? could be interesting for this, too.

Community
  • 1
  • 1
Mighty Badaboom
  • 6,067
  • 5
  • 34
  • 51