C#.net中如何在TextBox中显示数据库查询结果?

来源:百度知道 编辑:UC知道 时间:2024/06/17 06:02:07
我在设计中设置了四个ListBox,分别表示年月,也就是从x年x月到x年x月的一个工具出入库数量的查询。
下面是我的代码:
string toolName;
string year1,month1,year2,month2,status;

year1 = lstYear1.SelectedItem.Text;
month1 = lstMonth1.SelectedItem.Text;
year2 = lstYear2.SelectedItem.Text;
month2 = lstMonth2.SelectedItem.Text;
status = lstStatus.SelectedItem.Text;
toolName = txtToolName.Text.Trim();
SqlConnection con = new SqlConnection("server=.;database=mtc;Integrated Security=True ");
con.Open();
string tools = "select * from mtctoolstable where toolName='"+toolName+"'";
SqlCommand cmd = new SqlCommand(tools, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
txtToolName.Text = dr.GetString(dr.GetOrdinal("toolName"));
}

string i = "select sum(toolNumber) from mtctoolstable where tooltime between year1+month1 and year2+month2 and toolsign=0 and toolName=toolName";
第二个toolName应该是个参数吧,应该
string i = "select sum(toolNumber) from mtctoolstable where tooltime between year1+month1 and year2+month2 and toolsign=0 and toolName='"+toolName+"'";
然后你的year1+month1 你看下结果是什么,是日期的格式吗?应该不是吧。
格式相同才能比较撒。 如果2008-1-1和20081 怎么比较。

报的是什么错你得贴出来啊 不然鬼知道你错在哪啊

偶的神 找不到你的错误,更别说解决了