如果使用.Net的话,你可以使用 服务器 窗口来自动生成连接字符串,
在视图(view)菜单里面,中文名字叫做"服务器资源管理器",在那里你可以建立一个数据库连接,然后直接把数据拖到form里面就可以,
by the way "服务器资源管理器"非常强大,你可以把他当作sql server来使用。可以在里面做很多事情,比如建表,视图,存储过程等等。
below is from MSDN,you can find a lot of technical article in MSDN if you search"stored procedure and VC"
good luck
Steps 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:
//Execute current Stored Procedure
_variant_t vEffected ;
pRecordset = pCmdPtr->Execute(&vEffected,NULL,NULL);
if (pRecordset->BOF || pRecordset->EndOfFile)
throw ;
// Get result set in the form of array
vtResultRows = pRecordset->GetRows(-1);
return vtResultRows.Detach() ;
}
catch(_com_error &e)
{
ATLTRACE((LPCSTR)e.Description());
}
vtResultRows.vt = VT_EMPTY ;
return vtResultRows.Detach();
}
// We Are Expecting That Stored Procedures Return ID for Entity to which
// NSERT/UPDATE/DELETE operation is being performed
return (long)pCmdPtr->Parameters->Item["RETURN_VALUE"]->Value ;
}
catch(_com_error &e)
{
ATLTRACE((LPCSTR)e.Description());
}
return 0;
}
Set qdserver=dbserver.CreateQueryDef( " ")
strSQL="EXEC [SP] @CODE_IN = 'BATCHEXCHANGE' "
With qdserver
.Connect="odbc;driver={SQL Server};database=datqbase;server=servername;pwd=123 "
.ReturnsRecords=True
.SQL = strSQL
Set rsBatch=.OpenRecordset(dbOpenSnapshot,dbSQLPassThrough)
End With