Date to String conversion problem

DaveMon
DaveMon used Ask the Experts™
on
Hello Experts,

I am working with displaying data on a form using  C# and I am having trouble displaying dates that are returned from a data adapter.  The integers and text string appear just fine, but I get the "Form1.cs(1235): Cannot implicitly convert type 'string' to 'System.DateTime' "   error.

here is the relevent code:private void btnFind_Click(object sender, System.EventArgs e)
{
try
{
      xConn = new sqlConn();
      xConn.connectMe("SELECT * FROM wh_checked WHERE order =" + txtOrder.Text + "");
      try
      {
      xConn.OLEComm.Connection = xConn.OLEConn;
      System.Data.OleDb.OleDbDataReader d = xConn.OLEComm.ExecuteReader();
            while (d.Read())
                                          
      // this part works fine retreiving a text value
      txtPuller.Text =System.Convert.ToString(d["puller".ToString()]);
                        
      // this part causes an error
      txtErrFound.text =System.Convert.ToString(d["pull_date"]);

thanks for your help in advance

Dave


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Guy Hengel [angelIII / a3]Billing Engineer
Most Valuable Expert 2014
Top Expert 2009

Commented:
is the field pull_date datetime already? then use
d.getDate( ... )
with the index of the column returned.
the datareader has a function to get you the index based on the field name, but I don't have the name in my mind right now..

Author

Commented:
yes the field is a datetime.  I dont know the index.    So you are saying that just because the field is a datetime there is a great deal more code just to display the information?

in vb.net:  -- identical code fetches dates, text and integers without changing code

Me.txtStopChk_order.Text = r("Order".ToString)    ' populate textboxes
Me.txtStopChk_hold_date.Text = r("hold_date".ToString) ' populate textboxes

there is very little information on this subject out there for me to learn from

Dave
Billing Engineer
Most Valuable Expert 2014
Top Expert 2009
Commented:
well, the following should work, to just display the date as string:

 txtErrFound.text = d["pull_date"].ToString();

now, if you want the datetime value:
 DateTime dt = d.getDate(d.getOrdinal("pull_date"));

so not "great deal" more code.

Author

Commented:
thanks that got it working,  I still have the problem in that I can only populate one textbox at a time,  when I try to do two, I get a no data exists for row/column.  But now I can populate with dates so I am happy   thanks

Dave

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial