本文介绍了如何使用数据库中的月份和年份在csv中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用(SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
使用(DataTable dt = new DataTable())
{
sda.Fill(dt);
我尝试过:
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
What I have tried:
double Month = Convert.ToDouble(DropDownList1.SelectedItem.Value);
double Year = Convert.ToDouble(DropDownList2.SelectedItem.Value);
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("SELECT a.FirstName +' '+ a.MiddleName +' '+a.LastName as ApplicantName,a.ApplicationNo,b.[ApplicationDate] FROM [Applicant]as a,Application as b where a.ApplicationNo= b.ApplicationNo and MONTH(b.ApplicationDate) = @Month and YEAR(b.ApplicationDate) = @Year "))
//using (SqlCommand cmd = new SqlCommand("SELECT a.FirstName +' '+ a.MiddleName +' '+a.LastName as ApplicantName,a.ApplicationNo,b.[ApplicationDate] FROM [Applicant]as a,Application as b where a.ApplicationNo= b.ApplicationNo and YEAR(b.ApplicationDate) = @Year "))
{
SqlParameter param = new SqlParameter();
param.ParameterName = "@Month";
param.Value = Month;
cmd.Parameters.Add(param);
//SqlParameter param = new SqlParameter();
param.ParameterName = "@Year";
param.Value = Year;
cmd.Parameters.Add(param);
推荐答案
这篇关于如何使用数据库中的月份和年份在csv中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!