显示标签为“variables”的博文。显示所有博文
显示标签为“variables”的博文。显示所有博文

2012年3月29日星期四

bcp_bind and SQL DATETIME type

Hi all,
I'm working on a simple ODBC API bulk load application and I've run
into a problem. I am binding variables in memory and sending the rows
as prescribed in the ODBC 3.0 API Reference and on MSDN. Everything
works fine for SQL VARCHAR and SQL INTEGER data types; however, I run
into issues when I try to bind SQL DATETIME data types. I can't seem
to find examples of how this should be done anywhere... Should my
variable that I'm binding to be a C-Style string or a
SQL_TIMESTAMP_STRUCT or a time_t structure? It's all a blur...
Anyone know where I can find a sample that bcp_binds to a DATETIME
column in a table?
TIANever mind, issue resolved.
"Michael C#" wrote:

> Hi all,
> I'm working on a simple ODBC API bulk load application and I've run
> into a problem. I am binding variables in memory and sending the rows
> as prescribed in the ODBC 3.0 API Reference and on MSDN. Everything
> works fine for SQL VARCHAR and SQL INTEGER data types; however, I run
> into issues when I try to bind SQL DATETIME data types. I can't seem
> to find examples of how this should be done anywhere... Should my
> variable that I'm binding to be a C-Style string or a
> SQL_TIMESTAMP_STRUCT or a time_t structure? It's all a blur...
> Anyone know where I can find a sample that bcp_binds to a DATETIME
> column in a table?
> TIA
>|||Hello Michael,
Can you please show me an example that "works fine for SQL VARCHAR"? I just
can't send text using the bcp...
TIA
quote:
Originally posted by Michael C
Never mind, issue resolved.
"Michael C#" wrote:

> Hi all,
> I'm working on a simple ODBC API bulk load application and I've run
> into a problem. I am binding variables in memory and sending the rows
> as prescribed in the ODBC 3.0 API Reference and on MSDN. Everything
> works fine for SQL VARCHAR and SQL INTEGER data types; however, I run
> into issues when I try to bind SQL DATETIME data types. I can't seem
> to find examples of how this should be done anywhere... Should my
> variable that I'm binding to be a C-Style string or a
> SQL_TIMESTAMP_STRUCT or a time_t structure? It's all a blur...
> Anyone know where I can find a sample that bcp_binds to a DATETIME
> column in a table?
> TIA
>

|||Hi Michael, i am facing similar issue i.e. failing of bcp_binf for datetime
datatpye. Can You please share the solution that you have for this issue?
Thanks in advance.
From http://developmentnow.com/g/111_200...
ype.htm
Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

bcp_bind

Hi experts,
I created a program loading data from diferent sources to SQL Server
database by using bcp_... bulk copy functions with some variables.(not from a
file)
My problem is: Now, a table, "Person", has 10 columns. I bound 10 variables
to the 10 columns, and load data is fine. But if in the future the table
needs increase 1 column to 11 columns and run the existing program, it will
get the error "HY000--
Not enough columns bound.". That means "bcp_bind" function has to bind to
all the columns of the table. otherwise the binding will fail. If load data
from a file, I can use "bcp_columns" function to specify column number. But I
insert data from variables, how can I bind to only partial columns of a table?
Thank you.
MCH
I have the same question. Did you figure our how to do so?
Thank you very much
Yev
EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
|||always bind to a view of a table, not directly to a table, so you can control
the columns you want to bind.
MCH
"Yevheniy" wrote:

> I have the same question. Did you figure our how to do so?
> Thank you very much
> Yev
> EggHeadCafe.com - .NET Developer Portal of Choice
> http://www.eggheadcafe.com
>
sql

2012年3月11日星期日

BCP in using bcp_sendrow fails, not enough columns bound

Hello, first posting:
I am using bcp_sendrow to INSERT data from program variables into the
database.
I am sending less columns than the database contains, because new
columns need to be added to the tables before the program is changed.
However, despite the fact that the unspecified columns have default
values associated with them, I still get the error message:
"Not enough columns bound"
every time I attempt to insert a line. It does not matter if the
column is NULLable or not, I have determined that it will fail if the
unspecified columns are at the end of the table. Unspecified columns
in the middle of the table automatically get populated with the default
value or NULL.
Has anyone else come across this problem? Is there some sort of switch
I can use to make this work? The only solution I have come up with is
to insert new columns in the middle of the table, which I shouldn't
have to do (and it's slow at that).
Thanks in advance,
RobBind all columns and set the columns to ignore as NULL like this:
r = bcp_bind(hdbc, /* Database Handle */
(const LPCBYTE)"", /* Empty String */
0, /* 0 prefix len */
SQL_NULL_DATA, /* length of -1 = set column to NULL */
(const LPCBYTE)"", /* Terminator Char */
1, /* Terminator Length = 1 for \0x00 */
SQLCHARACTER, /* Column type */
Col_Num /* Column Number */
);
"Robert B" <rob@.automatedfinancial.com> wrote in message
news:1148604213.015728.148440@.38g2000cwa.googlegroups.com...
> Hello, first posting:
> I am using bcp_sendrow to INSERT data from program variables into the
> database.
> I am sending less columns than the database contains, because new
> columns need to be added to the tables before the program is changed.
> However, despite the fact that the unspecified columns have default
> values associated with them, I still get the error message:
> "Not enough columns bound"
> every time I attempt to insert a line. It does not matter if the
> column is NULLable or not, I have determined that it will fail if the
> unspecified columns are at the end of the table. Unspecified columns
> in the middle of the table automatically get populated with the default
> value or NULL.
> Has anyone else come across this problem? Is there some sort of switch
> I can use to make this work? The only solution I have come up with is
> to insert new columns in the middle of the table, which I shouldn't
> have to do (and it's slow at that).
>
> Thanks in advance,
> Rob
>|||Thanks, Mike,
I have no problem binding to a column and inserting NULL data. My
problem is that my program will fail with "not enough columns bound" as
soon as a new column is added to the table, even if the new column is
set to NULL, default NULL. I need to maintain some sort of
backwards-compatibility where the program will continue to work even
though I have not specified all the columns.
Rob|||I'm working on a similar problem myself right now. The fix I'm looking at
is to grab the column information from the table ahead of time and bind the
columns dynamically using that information. The info is available in the
INFORMATION_SCHEMA views, and I'm also testing a couple of other methods
myself. It's definitely more work, but definitely necessary in my case.
"Robert B" <rob@.automatedfinancial.com> wrote in message
news:1148659354.289141.188110@.j55g2000cwa.googlegroups.com...
> Thanks, Mike,
> I have no problem binding to a column and inserting NULL data. My
> problem is that my program will fail with "not enough columns bound" as
> soon as a new column is added to the table, even if the new column is
> set to NULL, default NULL. I need to maintain some sort of
> backwards-compatibility where the program will continue to work even
> though I have not specified all the columns.
> Rob
>