|
-
Jan 16th, 2008, 12:28 AM
#1
Thread Starter
PowerPoster
Command object use to add data to a database
Hi all,
I want to add a string and a character to two columns of a sql database table. To do that I use a Command object rather to use the same connection on different functions. At the same time used a stored procedure to add data.
Hear are some code segments.
Code:
// VC++ code use to add data
void CDbService::AddGData(string& fileName)
{
_CommandPtr pCom;
pCom.CreateInstance(__uuidof(Command));
pCom->ActiveConnection = m_pConn;
pCom->CommandType = adCmdStoredProc;
pCom->CommandText = _bstr_t("sp_GroupState");
// Add file name
pCom->Parameters->Append(pCom->CreateParameter(_bstr_t("FileName"), adVarChar, adParamInput, 50,&fileName));
}
Here is the stored procedure I used
Code:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
CREATE PROCEDURE [dbo].[sp_GroupState]
@FileName varchar, @State varchar
As
Insert into tblGroupState(DiskFileName, FileState)
Values (@FileName, @State);
But this code not added any data to my table. Here is the table create query I used.
Code:
USE [RFDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblGroupState](
[DiskFileName] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[FileState] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
Can you guys see any mistake I have made. It's really appreciate.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|