Click here to Skip to main content
15,921,841 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i am clik in search button they show error
< " incorrect syntex near tha keyword 'values'">

plz help me out for this problem
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

public partial class Update : Form
{
    SqlConnection con;
    SqlDataReader dr;
    public Update()
    {
        InitializeComponent();
    }
    private void Update_Load(object sender, EventArgs e)
    {
        con = new SqlConnection("Data Source=.;Initial Catalog=alsofi;Integrated Security=True");


    }

    private void groupBox1_Enter(object sender, EventArgs e)
    {

    }

    private void button6_Click(object sender, EventArgs e)
    {        
        try
        {
            con.Open();
            String q = "Select * from Development_Detal values where EmpId='" + EmpID.Text + "'";
            SqlCommand cmd = new SqlCommand(q, con);
            
            if (EmpID.Text == "")
            {
                MessageBox.Show("Search cannot be made for Null valuse Insert EmpID ");
            }
            else
            {
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {   
                    Ename.Text = dr.GetValue(0).ToString();
                    UserPass.Text = dr.GetValue(1).ToString();

                    emaill.Text = dr.GetValue(4).ToString();
                    textBox1.Text = dr.GetValue(5).ToString();
                    address.Text = dr.GetValue(3).ToString();
                    mobNo.Text = dr.GetValue(6).ToString();
                    city.Text = dr.GetValue(7).ToString();
                    MessageBox.Show("Search sucess");

                }
            }
        }
            
        catch(Exception ex)
        {
          MessageBox.Show(ex.Message);
        }
        finally
        {
            con.Close();
        }
      }
   }


Thanks in advance
Posted
Updated 24-Feb-13 21:36pm
v2

hii buddy

the main problem that you r using values keyword for select query...

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
 
public partial class Update : Form
{
    SqlConnection con;
    SqlDataReader dr;
    public Update()
    {
        InitializeComponent();
    }
    private void Update_Load(object sender, EventArgs e)
    {
        con = new SqlConnection("Data Source=.;Initial Catalog=alsofi;Integrated Security=True");
 

    }
 
    private void groupBox1_Enter(object sender, EventArgs e)
    {
 
    }
 
    private void button6_Click(object sender, EventArgs e)
    {        
        try
        {
            con.Open();
//main error is here remove values....
//String q = "Select * from Development_Detal values where EmpId='" + EmpID.Text + "'";
String q = "Select * from Development_Detal where EmpId='" + EmpID.Text + "'";
            SqlCommand cmd = new SqlCommand(q, con);
            
            if (EmpID.Text == "")
            {
                MessageBox.Show("Search cannot be made for Null valuse Insert EmpID ");
            }
            else
            {
                dr = cmd.ExecuteReader();
                while (dr.Read())
                {   
                    Ename.Text = dr.GetValue(0).ToString();
                    UserPass.Text = dr.GetValue(1).ToString();
 
                    emaill.Text = dr.GetValue(4).ToString();
                    textBox1.Text = dr.GetValue(5).ToString();
                    address.Text = dr.GetValue(3).ToString();
                    mobNo.Text = dr.GetValue(6).ToString();
                    city.Text = dr.GetValue(7).ToString();
                    MessageBox.Show("Search sucess");
 
                }
            }
        }
            
        catch(Exception ex)
        {
          MessageBox.Show(ex.Message);
        }
        finally
        {
            con.Close();
        }
      }
   }
 
Share this answer
 
Comments
Syed Shahabuddin 25-Feb-13 3:50am    
Thank u very much sir
:)
Shubh Agrahari 25-Feb-13 3:52am    
ok ma pleasure but if you got your answer its good to make a click to "Accept Solution"....that help us to help you
Try the following :
C#
String q = "Select * from Development_Detal where EmpId='" + EmpID.Text + "'";
 
Share this answer
 
Comments
Syed Shahabuddin 25-Feb-13 3:46am    
i am giving same bro
Syed Shahabuddin 25-Feb-13 3:49am    
thanks brother i have mistake thankx alot
:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900