在C#-reg中绑定DateTimepicker [英] Binding a DateTimepicker in C# -reg

查看:68
本文介绍了在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"

推荐答案

尊敬的Aharisankar,

只需尝试以下操作:
Dear Aharisankar,

Just try the following:
txtDate.Text = (Convert.ToDateTime(reader["DATE"])).ToString("dd/MM/yyyy"); ;



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

问候!
阿曼



I hope that it will work if its not databinding error

Regards!
Aman


嗨...

关于例外...
检查阅读器中是否实际有名称为"DATE"的字段.尝试将值分配给一个简单的文本框.仍然,如果您遇到异常,则很明显读者没有名称为"DATE"的字段.

关于ToString ...请尝试以下..

Hi...

Regarding the exception...
Check if you actual have field with name "DATE" in the reader. Try to assign value to a simple textbox. Still if u get exception then it''s clear the reader is not having a fields with name "DATE".

Regarding ToString... try following..

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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