1、简述利用MS SQL Server创建数据库test及上述两个数据表的过程。创建test数据库,定位到test库,创建两个表    2、分别给出对KHZLB进行插入、修改、删除以及查询的SQL脚本,其中查询时要求在结果
集中显示“客户类别说明”而不显示“客户类别编号”。
insert khzlb (khlbsm,qt) values('aa','bb')
update khzlb set khlbsm='aa',qt='bb' where khlbid=1
delete khzlb where khlbid=1    3、选择使用ODBC、ADO、DAO或DbLib等数据库访问技术的一种,用简单的描述性语言给
出访问(查询、插入、修改、删除)上述数据库的框架程序(VC++),若能用VC++给出程序实
例则更好。参考:below is from MSDN,you can find a lot of technical article in MSDN if you search"stored procedure and VC"
good luckSteps To Reproduce Behavior
In the SQL Server 7.0 Query Analyzer select the test database Pubs.
Create the following stored procedure. This stored procedure returns a recordset and an out parameter count.if exists (select * from sysobjects where id = object_id(N'[dbo].[GetJobs]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop proc GetJobs
   go
   create proc GetJobs @id as int, @count as int [out] as
   begin
    Select @count = Count(*) from jobs where job_id >@id
    Select * from jobs where job_id >@id
   end
   go
 Use VC App Wizard to create a new console application and modify the code as follows:#include "stdafx.h"
   #include "stdio.h"
   #import "C:\PROGRA~1\COMMON~1\System\ado\msado15.dll" no_namespace rename ("EOF", "EOF2")   struct InitOle {
     InitOle()  { ::CoInitialize(NULL); }
     ~InitOle() { ::CoUninitialize();   }
   } _init_InitOle_;   int main(int argc, char* argv[])
   {
    _variant_t varErr((long)0, VT_ERROR);
    _CommandPtr comm(__uuidof(Command));
    _ConnectionPtr conn(__uuidof(Connection));    _bstr_t connstr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=(local)";
    conn->Open(connstr, "", "", adConnectUnspecified);
    comm->ActiveConnection=conn;
    comm->CommandText="GetJobs";
    comm->CommandType = adCmdStoredProc ; 
    comm->Parameters->Refresh();
    _variant_t recs;    comm->Parameters->Item[_variant_t((short)1)]->Value= _variant_t((long)5);
    _RecordsetPtr rs = comm->Execute(&recs, &vtMissing,adCmdStoredProc);     _variant_t recordcount= comm->Parameters->Item[_variant_t((short)2)]->Value;    printf("recordcount = %li\n", (long)recordcount);
    return 0;
   }
 
Change the Datasource, User ID and password in the connection string above.
The recordcount variant that the above code returns is of type VT_NULL rather than the number of records that the stored procedure returns.

解决方案 »

  1.   

    1:
    CREATE DATABASE [test]  ON (NAME = N'test_Data', FILENAME = N'd:\Microsoft SQL Server\MSSQL\data\TX.mdf' , SIZE = 173, FILEGROWTH = 10%) LOG ON (NAME = N'test_Log', FILENAME = N'd:\Microsoft SQL Server\MSSQL\data\test_log.LDF' , SIZE = 3, FILEGROWTH = 10%)
    go
    create table KHZLB 
    (       
    khid int            IDENTITY ,   --客户编号
    khlbid         int             not null ,   --客户类别编号
    khxm            varchar(20)       not null ,   --客户姓名
    sjhm            varchar(20)             not null ,   --手机号码
    txdz            varchar(100)       not null ,   --通讯地址
    qt varchar(100) null      --其他
    CONSTRAINT [PK_KHZLB] PRIMARY KEY  CLUSTERED 
    (
    khid
    )  ON [PRIMARY] ,
    ) ON [PRIMARY]
    GOcreate table KHLBB
    (
    khlbid int IDENTITY ,   --客户类别编号
    khlbsm varchar(20) not null ,   --类别说明
    qt varchar(50) null      --其他
    CONSTRAINT [PK_KHLLB] PRIMARY KEY  CLUSTERED 
    (
    khlbid
    )  ON [PRIMARY] ,
    ) ON [PRIMARY]
    go2:
    insert khzlb values(1,1,'沃尔玛','1234567890123','地址不告诉你','一级客户 ') update khzlb set sjhm = '2345678901231' where khid = 1delete khzlb where khlbid = 2select a.khid,b.khlbsm from khzlb a join khlbb b on a.khlbid = b.khlbid