Showing posts with label mdb. Show all posts
Showing posts with label mdb. Show all posts

Friday, February 24, 2012

How to retrieve Date fields from an Access MDF on VS c++ Net 2005

I Apologize if this isn't the forum to ask this...
I have a MS Access (MDB) file with a table with 2 date fields, i want to read from a dialog on my app (on MS Visual .NET Studio 2005), here's the code I've been using do far:

Code Snippet

hr=theApp.m_cs.Open(theApp.m_ds);
if(SUCCEEDED(hr)) {

theApp.m_cs.StartTransaction();

theApp.m_cs.Commit();
CCommand< CDynamicAccessor > cmd;
CComBSTR query(_T("SELECT NumContrato, NumClie, FechaC, FechaCob, Inversion, NoCobrador, NoVendedor, Total, Plazo, Pagos FROM Contrato"));
CString string(query.m_str);
cmd.Open(theApp.m_cs,string);

hr = cmd.MoveFirst();

query=static_cast< BSTR >(cmd.GetValue(1));
CString csres(query.m_str);
this->m_numc=(int)*(query.m_str);
query=static_cast< BSTR >(cmd.GetValue(2));
m_numcte=(int)*(query.m_str);
query=static_cast< BSTR >(cmd.GetValue(3));
//m_fecc=(int)*(query.m_str);

MessageBox(csres);
theApp.m_cs.Close();
}



FechaC, FechaCob, are the two Dates I want to retrieve, but when I debug, it reads a 0 (zero) from the date fields, is there a limitation? can they be read? is there a special way to read them?
> thanks in advance!

--
Me!

I'm not experienced in templates, but it looks strange for me and you should check the type of the returned value.

If your field is of the type Date/Time then I'm not sure that simple casting is correct, since I would expect GetValue to return the pointer into the buffer with the actual data and I presume that the datatype there should be DBTYPE_DATE. Perhaps you need to create a specific accessor and explicitly request conversion to a string type.

|||Thanks A lot this is what i've done:

Code Snippet

DATE *d=(DATE*)(cmd.GetValue(3));

COleDateTime D(*d);

m_fec=D;

Sorry for the such a noob question you've been helpful! :)!

Sunday, February 19, 2012

how to restore the sqlserver2000s mdb files to another sqlserver

Hi there,
My sqlserver 2000 was down(means failed to reload ) I just copied all the mdb files and log files from that server. now i wants to reload my databases from the mdb files. is it possible?. If so pls inform me how to do that.
Its very urgent. Pls help me:
confused:If you have all of the MDF and LDF files look into using SP_ATTACH_DB. After that you'll need to recreate the logins in MASTER from those in your databases.