日期时间选择器 - 时间不会改变 [英] date time picker - time does not change

查看:57
本文介绍了日期时间选择器 - 时间不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,需要一些专家的建议和帮助。我是NooB,试图创建一个小的Windows窗体应用程序,将一些数据插入到我的SQL数据库中。在此表单上,我使用3个组合框,1个文本框,1个日期时间选择器和一个按钮进行保存操作。应用程序工作正常,按照预期的方式工作,但唯一的问题是每个记录插入表后时间都不会更新。时间保持不变。以下是代码,请帮忙。



问候

Jagadish K



Guys, Need some expert advise and help. I am a NooB, trying to create a small Windows Form Application that would insert some data into MY SQL Database. On this form, I am using 3 Combo Box, 1 Text Box, 1 Datetime picker and one button for the save action. The Application works fine, the way it is intended to, but the only problem is time does not get updated after every record is inserted to the table. Time remains Constant. Below is the Code, kindly help.

Regards
Jagadish K

private void Save_Click(object sender, EventArgs e)
{           
      string sDispatcher = DispatcherName.Text;
      string sDPSNum = DispatchNumber.Text;
      string sDPSType = DPSType.Text;
      DateTime dtDT = dateTimePickerDT.Value;
      string sQueue = QG.Text;

      string query = "INSERT INTO dps_data(DispatcherName, DispatchNumber, DPSType, DateTime, Queue)" +"VALUES( @Dispatcher, @DPSNum, @DPSType, @DT, @Queue)";

      SqlConnection conn = new SqlConnection(connection);
      SqlCommand cmd = new SqlCommand(query, conn);
      conn.Open();

      cmd.Parameters.Add(new SqlParameter("@Dispatcher", sDispatcher));
      cmd.Parameters.Add(new SqlParameter("@DPSNum", sDPSNum));
      cmd.Parameters.Add(new SqlParameter("@DPSType", sDPSType));
      cmd.Parameters.Add(new SqlParameter("@DT", dtDT));
      cmd.Parameters.Add(new SqlParameter("@Queue", sQueue));

      int result = cmd.ExecuteNonQuery();
      if (result > 0)
      {
         MessageBox.Show("Data Added Successfully");
      }
      else
      {
         MessageBox.Show("Error in Adding Data");
      }          

      conn.Close();

      DispatchNumber.Text = String.Empty;
      DPSType.Text = String.Empty;
      QG.Text = String.Empty;
   }
}




推荐答案

它不会插入,因为你的dtDT变量不包含在你的insert语句中。

你需要将它添加到 string query =INSERT INTO dps_data(DispatcherName,DispatchNumber,DPSType,DateTime,Queue)+VALUES(@ Dispatcher,@ DdNum,@ DPSType,@ DT,@ Queue); 语句作为另一个参数。
It won''t insert because your dtDT variable is not included in your insert statement.
You need to add it to the string query = "INSERT INTO dps_data(DispatcherName, DispatchNumber, DPSType, DateTime, Queue)" +"VALUES( @Dispatcher, @DPSNum, @DPSType, @DT, @Queue)"; statement as another parameter.


这篇关于日期时间选择器 - 时间不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆