在窗口应用程序中搜索c#中的问题 [英] search problem in c# in window application
本文介绍了在窗口应用程序中搜索c#中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在搜索按钮中时,他们显示错误
< 不正确的syntex靠近关键字''值''>
plz帮我解决这个问题
when i am clik in search button they show error
< " incorrect syntex near tha keyword ''values''">
plz help me out for this problem
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
推荐答案
请尝试以下方法:
Try the following :
String q = "Select * from Development_Detal where EmpId='" + EmpID.Text + "'";
hii buddy
你为选择查询使用值关键字的主要问题...
hii buddy
the main problem that you r using values keyword for select query...
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();
}
}
}
这篇关于在窗口应用程序中搜索c#中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文