Friday, February 24, 2012

Blob and MFC

I'm using MFC(Visual C++ 6.0), SQL Server 2000 and ODBC to connect to SQL Se
rver. I have a table that has a blob(image) column in it. The structure of t
he table is:
CREATE TABLE [dbo].[lbx_blob_1096] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[Date] [varchar] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Refno] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[imgData] [image] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
I have a Stored Procedure thru which I would like to insert data and image i
nto the table. The Stored Procedure is defined as follows:
CREATE proc dbo.CMS_sp_inserttoblobtable
@.blobtablename varchar(50),
@.valuesstr varchar(100),
@.resultparam int output
as
BEGIN TRAN INSERT_BLOBTABLE
DECLARE @.retval int
EXEC('INSERT INTO ' + @.blobtablename + ' (busdate,refno,imgData) VALUES ( '
+ @.valuesstr + ' )')
IF @.@.ERROR <> '0'
BEGIN
ROLLBACK TRAN INSERT_BLOBTABLE
END
ELSE
BEGIN
COMMIT TRAN INSERT_BLOBTABLE
SET @.resultparam = @.@.IDENTITY
END
SET @.retval = @.@.ERROR
RETURN @.retval
GO
I would like to know of a easy way to pass the image data from my MFC applic
ation to the Stored Procedure. Rightnow, I'm trying to use the SQLBindParame
ter as :
retValue = SQLBindParameter(hstmt, 5, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_BIN
ARY,0, 0, (SQLPOINTER)s_ImgData, 0, &cbBinary);
But, I keep getting a datatype mismatch error. Can anybody please help me on
this?
Thanks,I don't think you can update BLOB fields from MFC using a SP. I think you'll
need to look into using the either the ADO GetChunk and AppendChunk methods
or the ADO Stream object. Here's a couple pieces of information that might
help:
http://support.microsoft.com/defaul...kb;en-us;189415
http://support.microsoft.com/defaul...kb;en-us;258038
Mike O.
"Mohan K" <anonymous@.discussions.microsoft.com> wrote in message
news:C8B747B6-7E2B-48A0-9219-DFF0500180AA@.microsoft.com...
> I'm using MFC(Visual C++ 6.0), SQL Server 2000 and ODBC to connect to SQL
Server. I have a table that has a blob(image) column in it. The structure of
the table is:
> CREATE TABLE [dbo].[lbx_blob_1096] (
> [ID] [int] IDENTITY (1, 1) NOT NULL ,
> [Date] [varchar] (11) COLLATE SQL_Latin1_General_CP1_CI_AS NU
LL ,
> [Refno] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NU
LL ,
> [imgData] [image] NOT NULL
> ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
> GO
> I have a Stored Procedure thru which I would like to insert data and image
into the table. The Stored Procedure is defined as follows:
> CREATE proc dbo.CMS_sp_inserttoblobtable
> @.blobtablename varchar(50),
> @.valuesstr varchar(100),
> @.resultparam int output
> as
> BEGIN TRAN INSERT_BLOBTABLE
> DECLARE @.retval int
> EXEC('INSERT INTO ' + @.blobtablename + ' (busdate,refno,imgData)
VALUES ( ' + @.valuesstr + ' )')
> IF @.@.ERROR <> '0'
> BEGIN
> ROLLBACK TRAN INSERT_BLOBTABLE
> END
> ELSE
> BEGIN
> COMMIT TRAN INSERT_BLOBTABLE
> SET @.resultparam = @.@.IDENTITY
> END
> SET @.retval = @.@.ERROR
> RETURN @.retval
> GO
> I would like to know of a easy way to pass the image data from my MFC
application to the Stored Procedure. Rightnow, I'm trying to use the
SQLBindParameter as :
> retValue = SQLBindParameter(hstmt, 5, SQL_PARAM_INPUT, SQL_C_BINARY,
SQL_BINARY,0, 0, (SQLPOINTER)s_ImgData, 0, &cbBinary);
> But, I keep getting a datatype mismatch error. Can anybody please help me
on this?
> Thanks,

No comments:

Post a Comment