本文介绍了在C#-reg中绑定DateTimepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在C#的Windows程序中绑定Datetimepicker.我可以将datetimepicker中的日期插入到sqlserver中,但是不幸的是我无法从数据库中检索日期.显示错误.如何在C#中绑定datetimepicker?
谁能帮我吗?
我的代码是

I just want to bind Datetimepicker in my windows program in C#. I can insert date from datetimepicker to sqlserver but unfortunately I can not retrieve date from database. It shows an error. How to bind datetimepicker in C#?
Can anyone help me please?
MY CODE IS

private void BindReader(string storedproc,string[] param)
      {
          clear();
          reader = ppt.ParamReader(storedproc,param ); // Here searching a Branch Name and binding values in matching text box
          while (reader.Read())
          {
              lbl_ID.Text = reader["BRANCH_ID"].ToString();
              txt_Address.Text = reader["BRANCH_ADDRESS"].ToString();
              txt_Branch_Phone.Text = reader["BRANCH_PHONE"].ToString();
              txt_CST_Number.Text = reader["CST_NUMBER"].ToString();
              txt_tin_number.Text = reader["TIN_NUMBER"].ToString();
              cmb_Branch_Name.Text = reader["BRANCH_NAME"].ToString();
             txtDate.Text = reader["DATE"].ToString(); ;

          }
          reader.Close();
      }




我收到"indexOutOfRangeException was unhandled"错误
我尝试使用




I''m getting "indexOutOfRangeException was unhandled" error
I tried using

txtDate.Text = reader["DATE"].ToString("dd/mm/yyyy"); // DATETIME PICKER


它还显示错误"NO overload for method ToSting takes 1 arguments"


It also shows an error "NO overload for method ToSting takes 1 arguments"

推荐答案

txtDate.Text = (Convert.ToDateTime(reader["DATE"])).ToString("dd/MM/yyyy"); ;



我希望它不会出现数据绑定错误也能起作用

问候!
阿曼



I hope that it will work if its not databinding error

Regards!
Aman


txtDate.Text = String.Format("{0:dd/MM/yyyy}",reader["DATE"]);



这应该适合您.

谢谢和问候,
斯坦·兰帕里亚(Chetan Ranpariya)



This should work for you.

Thanks and regards,
Chetan Ranpariya


这篇关于在C#-reg中绑定DateTimepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 13:00