Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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();
      }



I'm getting "indexOutOfRangeException was unhandled" error
I tried using
txtDate.Text = reader["DATE"].ToString("dd/mm/yyyy"); // DATETIME PICKER

It also shows an error "NO overload for method ToSting takes 1 arguments"
Posted
Updated 20-Dec-10 1:15am
v6
Comments
Toniyo Jackson 20-Dec-10 5:37am    
What error getting?
JF2015 20-Dec-10 5:37am    
Edited to fix spelling errors.
Manfred Rudolf Bihy 20-Dec-10 5:39am    
Don't you think it would be appropriate to tell us what error you are receiving and maybe also show us the relevant part of your code?
We're not yet into mind reading. :)
Abhinav S 20-Dec-10 6:19am    
What's the error?
Aman4.net 22-Dec-10 7:58am    
As you know C# is case senstive so "dd/MM/yyyy" is different from "dd/mm/yyyy" use first one

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
 
Share this answer
 
v2
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"]);


This should work for you.

Thanks and regards,
Chetan Ranpariya
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900