Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 problem when using bcp for datetime field

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-07-26 : 09:47:02
Srikanth writes "i'm trying to do bcp(bulk copy program) into a table having a field with datetime as the data

type using DB- library
I'm using MS SQL Server 2000.
Enterprise Edition on Windows NT 5.0 (Service Pack 2)

The language settings is English(United States) and
in the DB-Library OPtions of the Client Network Utility ,
the "Use International Settings" option is checked.
Also, in the Regional Settings(Control Panel), the short format is M/d/yyyy
(7/19/2001 for eg)



the piece of code could be summarised like this

DBPROCESS *pdbproc;
LOGINREC *ploginrec;

UINT nRowsSent = 0;
ploginrec = ::dblogin();
DBSETLUSER(ploginrec, "sa");
DBSETLVERSION(ploginrec, DBVER60);
DBSETLPWD(login, "");

BCP_SETL(ploginrec, TRUE);
pdbproc = ::dbopen(ploginrec, "PARKER");


if (bcp_init(pdbproc, "daily_data", (BYTE *)NULL,(BYTE *)NULL, DB_IN) == FAIL)
return -1;

TCHAR sDate[] = "07/09/1999";
//for brewity i have included only the column in which i'm binding the date variable which is the

//second column of the table

if (bcp_bind(pdbproc, (LPCBYTE)sDate, (DBINT)0, (DBINT)-1, (BYTE*)"\0",1,SQLDATETIME,2) == FAIL)

{
cout << "bcp_bind in column No.2 failed" << endl;
return -1;
}

//more code binding columns omitted
if(bcp_sendrow(pdbproc) == FAIL)
{
cout << "Error- bcp sendrow failed" << endl;
return -1;
}

if(bcp_batch(pdbproc) == (-1))
{
cout << "Error- bcp batch failed" << endl;
return -1;
}


if ((nRowsSent = bcp_done(pdbproc)) == -1)
{
cout << "Error- bcp done failed" << endl;
return -1;
}
else
cout << "Successfully performed Bulk Copy " << endl;


i will be grateful if any one could give me a solution

thank you
srikanth"
   

- Advertisement -