怎么能在列表框中看到总veichle赋值日期 [英] how can see total veichle assignment date wise in list box
问题描述
我创建了一个表城市,veichle,assigndate,我在其中插入值但我怎样才能在列表框中看到
i在网络表单上有日历和列表框,我的代码是....
I have create one table city, veichle,assigndate where i insert value but how can i see on listbox
i have calender and listbox on web form and my code is....
SqlCommand cmd = new SqlCommand("select count(*)as from Assvechle where assdate='"+calenderid.SelectedDate +"' ", con);
SqlDataReader dr = cmd.ExecuteReader();
ListBox1.DataSource = dr;
ListBox1.DataTextField = "total";
ListBox1.DataTextField = "city";
ListBox1.DataValueField = "";
ListBox1.DataBind();
con.Close();
}
有错误
there is error
推荐答案
从查询中删除AS:
Remove the "AS" from your query:
SqlCommand cmd = new SqlCommand("select count(*)as from Assvechle where assdate='"+calenderid.SelectedDate +"' ", con);
成为:
Becomes:
SqlCommand cmd = new SqlCommand("select count(*) from Assvechle where assdate='"+calenderid.SelectedDate +"' ", con);
但请使用参数化查询!
But please, use a parameterized query!
我建议您使用存储程序 [ ^ ]代替后面的查询,因为 sql注入 [ ^ ]。
I'd suggest you to use stored procedure[^] instead a query in code behind, because of sql injection[^].
CREATE PROCEDURE GetCountOfCityOnDate
@assdate DATETIME
AS
BEGIN
SELECT city, count(*) AS Total
FROM Assvechle
WHERE assdate = @assdate
GROUP BY city
END
如需了解更多信息,请参阅:
如何:保护ASP.NET中的SQL注入 [ ^ ]
在停止之前停止SQL注入攻击 [ ^ ]
SQL注入及其如何避免 [ ^ ]
演练:使用GridView Web服务器控件中的存储过程显示数据 [ ^ ]
< a href =http://msdn.microsoft.com/en-us/library/d7125bke.aspx>如何:执行返回行的存储过程 [ ^ ]
如何使用Visual Basic .NET在ASP.NET中调用SQL Server存储过程 [ ^ ]
For further information, please see:
How To: Protect From SQL Injection in ASP.NET[^]
Stop SQL Injection Attacks Before They Stop You[^]
SQL Injection and how to avoid it[^]
Walkthrough: Displaying Data Using a Stored Procedure in the GridView Web Server Control[^]
How to: Execute a Stored Procedure that Returns Rows[^]
How to call SQL Server stored procedures in ASP.NET by using Visual Basic .NET[^]
这篇关于怎么能在列表框中看到总veichle赋值日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!