C#2008 联接数据库查找某货品查找请教!
添加一个textBox5 在文本框中录入货品编码后点击button4 查找出该货品编码的相关编码
请问这个如何实现,谢谢!
private void button4_Click(object sender, EventArgs e)
{
string ConnectString = @"server=localhost;uid=sa;pwd=sankyqiu;database=yqerp2008";
SqlConnection conn = new SqlConnection(ConnectString);
SqlDataAdapter adapter;
DataSet ds; try
{
conn.Open();
adapter = new SqlDataAdapter("select goodsid as 货品ID,code AS 货品编码,name AS 货品名称,spec AS 货品规格 from goods ", conn); ds = new DataSet();
adapter.Fill(ds);
EmpGridView.DataSource = ds.Tables[0].DefaultView;
}
finally
{
conn.Close();
}
}
添加一个textBox5 在文本框中录入货品编码后点击button4 查找出该货品编码的相关编码
请问这个如何实现,谢谢!
private void button4_Click(object sender, EventArgs e)
{
string ConnectString = @"server=localhost;uid=sa;pwd=sankyqiu;database=yqerp2008";
SqlConnection conn = new SqlConnection(ConnectString);
SqlDataAdapter adapter;
DataSet ds; try
{
conn.Open();
adapter = new SqlDataAdapter("select goodsid as 货品ID,code AS 货品编码,name AS 货品名称,spec AS 货品规格 from goods ", conn); ds = new DataSet();
adapter.Fill(ds);
EmpGridView.DataSource = ds.Tables[0].DefaultView;
}
finally
{
conn.Close();
}
}
解决方案 »
- WPF 用xamlWriter读取richtextBox中document时去掉XAML标记
- 关于 网络通讯 封装类
- C# Winfrom 自动关闭
- 送分了哦!
- 对程序集“D:\oss\nHibernate\src\NHibernate\obj\Debug\NHibernate.dll”签名时加密失败 --“读取密钥文件“..\NHibernate.snk”时出错
- c#:foreach、IEnumrator、yield的理解
- c# 如何监控usb串口向电脑内传送的文件,并得到文件的信息
- smi 是什么文件,怎么和mpg在一起? edi 文件可以转换为xml ?
- 在自定义工具箱中添加 MSComm32.Ocx控件,为何出现“没有使用该控件的许可证"
- 急,急,急!紧急求助.
- 查询Access表主键
- C#的WINFORM窗体LABEL显示的问题
{
string ConnectString = @"server=(local);uid=sa;pwd=sankyqiu;database=yqerp2008";
SqlConnection conn = new SqlConnection(ConnectString);
SqlDataAdapter adapter;
DataSet ds; try
{
conn.Open();
adapter = new SqlDataAdapter("select goodsid as 货品ID,code AS 货品编码,name AS 货品名称,spec AS 货品规格 from goods extwhere goodsid = "+textbox5.text+"", conn); ds = new DataSet();
adapter.Fill(ds);
EmpGridView.DataSource = ds.Tables[0].DefaultView;
}
finally
{
conn.Close();
}
}
("select goodsid as 货品ID,code AS 货品编码,name AS 货品名称,spec AS 货品规格 from goods extwhere goodsid = "+textbox5.text+"", conn);
是不是改为以下呀,(textBox5.Text 分大小写)
adapter = new SqlDataAdapter("select goodsid as 货品ID,code AS 货品编码,name AS 货品名称,spec AS 货品规格 from goods where code = "+textBox5.Text+"", conn);
但执行有如下提示:
将 varchar值'****'转换类型为int列时发生语法错误.
比如输入了字母 或者其他非数字的字符
貌似你数据库里 code 字段是数值型的
adapter = new SqlDataAdapter("select goodsid as 货品ID,code AS 货品编码,name AS 货品名称,spec AS 货品规格 from goods where code = '+Convert.Toint32(textBox5.Text)+'", conn);
是不是" ' 的问题?
如果再报错那就是你数据库中code字段的数据类型与你textbox5输入的数据字段,类型不匹配了。
adapter = new SqlDataAdapter("select goodsid as 货品ID,code AS 货品编码,name AS 货品名称,spec AS 货品规格 from l_goods where code = '"+Convert.ToInt32(textBox5.Text)+" ' ", conn);这样就可通过运行,但是
如果在textBox5 里录入货品编码 009 后点击按钮却没显示出来!