Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# “我明白你的意思,那么我该如何继续下去呢?”?即使我要删除int a=todc1.execurteNonQuery,select查询仍然不会返回今天日期在2014年2月28日00:00:00到2014年3月1日之间的列…@johnymopp我有另一个表单,_C#_Sql_Winforms_Sql Server Express - Fatal编程技术网

C# “我明白你的意思,那么我该如何继续下去呢?”?即使我要删除int a=todc1.execurteNonQuery,select查询仍然不会返回今天日期在2014年2月28日00:00:00到2014年3月1日之间的列…@johnymopp我有另一个表单,

C# “我明白你的意思,那么我该如何继续下去呢?”?即使我要删除int a=todc1.execurteNonQuery,select查询仍然不会返回今天日期在2014年2月28日00:00:00到2014年3月1日之间的列…@johnymopp我有另一个表单,,c#,sql,winforms,sql-server-express,C#,Sql,Winforms,Sql Server Express,“我明白你的意思,那么我该如何继续下去呢?”?即使我要删除int a=todc1.execurteNonQuery,select查询仍然不会返回今天日期在2014年2月28日00:00:00到2014年3月1日之间的列…@johnymopp我有另一个表单,我使用两个datetimepicker控件选择两个独立的日期,比如2014年2月25日和2014年2月28日。。。该查询将运行这两天之间的所有行。我还使用了ExecuteOnQuery而不是ExecuteReader。它就像一个符咒……Exec


“我明白你的意思,那么我该如何继续下去呢?”?即使我要删除int a=todc1.execurteNonQuery,select查询仍然不会返回今天日期在2014年2月28日00:00:00到2014年3月1日之间的列…@johnymopp我有另一个表单,我使用两个datetimepicker控件选择两个独立的日期,比如2014年2月25日和2014年2月28日。。。该查询将运行这两天之间的所有行。我还使用了ExecuteOnQuery而不是ExecuteReader。它就像一个符咒……
ExecuteNonQuery
总是返回
-1
,因为您的命令是
SELECT
。请阅读文档。这不好!这个日期(字符串)是什么意思:2014年3月5日?是3月5日还是5月3日?使用通用YYYY-MM-DD.Use代替。@SonerGönül O.k.理解你的观点,那么我如何继续?即使我要删除int a=todc1.execurteNonQuery,select查询仍然不会返回今天日期在2014年2月28日00:00:00到2014年3月1日之间的列…@johnymopp我有另一个表单,我使用两个datetimepicker控件选择两个独立的日期,比如2014年2月25日和2014年2月28日。。。该查询将运行这两天之间的所有行。我还使用了ExecuteOnQuery而不是ExecuteReader。它就像一个符咒…我不认为这是OP想要的。他们想知道如何使用ExecuteReader和读取记录(显示在报告上)。我不认为这是OP想要的。他们想知道如何使用
ExecuteReader
和读取记录(显示在报告上)。好答案包括
ExecuteReader
和处理日期和参数-每个人都应该知道谁是小Bobby Tables!:-)在对数据库运行查询之前,
AddWithValue
是否将
DateTime
格式化为MySQL的'YYYY-MM-DD'格式?@DerekW,这是参数的目的,您不必指定格式。如果列类型为
DateTime
,则可以。然而,您使用的是MySQL或SqlServer,因为您的代码使用的是用于
SqlServer
的类,如果您的目标是MySQL数据库,那么就使用MySQL类。我不是OP。我只是一个好奇的旁观者。我总是将我的
DateTime
格式化为与RDBMS一起使用的正确格式,但ADO.NET中的
AddWithValue
功能似乎已经在为我这样做了。@DerekW,my bad:),是的,格式化
DateTime
,以便通过.NET framework(或任何其他)在SQL查询中使用就这一点而言,这不是一个好主意。大多数框架都支持带有查询的参数,它们将有助于解决格式问题,还可以将一个好答案保存为封面
ExecuteReader
,以及处理日期和参数-每个人都应该知道小Bobby Tables是谁!:-)在对数据库运行查询之前,
AddWithValue
是否将
DateTime
格式化为MySQL的'YYYY-MM-DD'格式?@DerekW,这是参数的目的,您不必指定格式。如果列类型为
DateTime
,则可以。然而,您使用的是MySQL或SqlServer,因为您的代码使用的是用于
SqlServer
的类,如果您的目标是MySQL数据库,那么就使用MySQL类。我不是OP。我只是一个好奇的旁观者。我总是将我的
DateTime
格式化为与RDBMS一起使用的正确格式,但ADO.NET中的
AddWithValue
功能似乎已经在为我这样做了。@DerekW,my bad:),是的,格式化
DateTime
,以便通过.NET framework(或任何其他)在SQL查询中使用就这一点而言,这不是一个好主意。大多数框架都支持带有查询的参数,它们将有助于解决格式问题,并从
SqlConnection tod1 = new SqlConnection(@"Data Source=2011-GOA-RCC3\SQLEXPRESS;Initial Catalog=IOB_Comm;Integrated Security=True");
tod1.Open();
SqlCommand todc1 = new SqlCommand();
todc1.Connection = tod1;

DateTime today = DateTime.Today;
//DateTime todayl = today.AddDays();
DateTime dnext = today.AddDays(1);
label4.Text = today.ToString("MMM dd yyyy 00:00");
label5.Text = dnext.ToString("MMM dd yyyy 00:00");
label6.Text = label4.Text;
label7.Text = label5.Text;

DateTime d1 = Convert.ToDateTime(label4.Text);
DateTime d2 = Convert.ToDateTime(label5.Text);
dateTimePicker3.Value = today;
dateTimePicker4.Value = dnext;

var d3 = Convert.ToString(label4.Text);
var d4 = Convert.ToString(label5.Text);
//todc.CommandText = "Select * from DCR Where Comp_Date >= '" + d1 + "' And Comp_Date <= '" + d2 + "' Order By Comp_Date Asc";
//todc.CommandText = "Select * from DCR Where Comp_Date '" + DateTime.Today + "'Order by Comp_Date Asc";
todc1.CommandText = "Select * from DCR Where Comp_Date >= '"+ dateTimePicker3.Text +"' And Comp_Date < '"+dateTimePicker4.Text+"' Order By Comp_Date Desc";
int a = todc1.ExecuteNonQuery();
label8.Text = a.ToString();
if (a > 0)
{
    //bind to report viewer
}
using (SqlConnection conn = new SqlConnection("connectionString"))
{
    using (SqlCommand todc1 = new SqlCommand("Select * from DCR Where Comp_Date >= @todayDate And Comp_Date < @nextDay Order By Comp_Date Desc", conn))
    {
        todc1.Parameters.AddWithValue("@todayDate", DateTime.Today);
        todc1.Parameters.AddWithValue("@nextDay", DateTime.Today.AddDays(1));

        DataTable dt = new DataTable();
        dt.Load(todc1.ExecuteReader());
        //bind to report viewer. 
        //yourReportViewer.DataSource = dt;
    }
}
sqlConnection.Open();
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandType = CommandType.Text;
sqlCommand.CommandText = "Select * from DCR Where Comp_Date >= @CurrentDate And Comp_Date < @nextDay Order By Comp_Date Desc";

sqlCommand.Parameters.Add("@CurrentDate", SqlDbType.VarChar).Value = adparam[0];
sqlCommand.Parameters.Add("@NextDate", SqlDbType.VarChar).Value = adparam[1];
sqlCommand.ExecuteNonQuery();

sqlDataAdapter sda = new SqlDataAdapter(sqlcommand);
DataTable dt = new DataTable();
sda.Fill(dt);