我试图通过sharepoint的DataFormWebPart通过传递当前登录的sharepoint用户名(本质上是一个服务器变量)来执行存储过程,但是,我在如何传递服务器变量的问题上遇到了困难。
下面是我的代码
<asp:SqlDataSource runat="server" ProviderName="System.Data.SqlClient" ID="SqlDataSource7" SelectCommandType="StoredProcedure" ConnectionString="xxx;" SelectCommand="xxx" __designer:customcommand="true">
<SelectParameters>
<!-- Not sure what to do here -->
</SelectParameters>
</asp:SqlDataSource>我知道我想做像这样的事情
<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>但似乎我只能使用asp参数标记...
发布于 2013-01-26 00:37:17
迟到总比不到好:)
我在2010年工作,但我想它在2007年也应该可以工作:
...
...
现在在SqlDataSource参数@Context :中有了当前的IIS用户(即DOMAIN\ user )
发布于 2011-11-16 13:24:21
我认为你永远不应该在你的页面中使用sqldatasource。
试试这条路
1.1添加类库(To go File -> New Project -> Add ClassLibrary)
2.1将类文件添加到类lib项目中,作为‘’Classbll‘
public class DBConnection
{
#region"private variables"
private string _sConnectionString = ConfigurationManager.AppSettings["DBConnectString"].ToString();
private static string _sErrorMessage = string.Empty;
#endregion
#region "Public Properties"
public string DataConnectionString
{
get
{
return _sConnectionString;
}
}
public string ErrorMessage
{
get
{
return _sErrorMessage;
}
set
{
_sErrorMessage = value;
}
}
#endregion
}2.2在主项目的web.config中定义连接字符串
<appSettings>
<add key="DBConnectString" value="SERVER=XYZSERVER;UID=XXYY;Password=ZZZXXX;Database=DBXXYYZZ;"/>
</appSettings>3现在在同一类库项目中创建另一个类文件。
假设文件名为“FillCommon.cs”
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Data;
using System.Web.UI.WebControls;
namespace Clssbll
{
public class FillCommon : DBConnection
{
#region "Private variables"
private string _smRoleMasterRoleID;
#endregion
#region "Public variables"
public string mRoleMasterRoleID
{
get { return _smRoleMasterRoleID; }
set { _smRoleMasterRoleID = value; }
}
#endregion
#region "Public Methods"
public DataSet GetmRoleMaster_infoSingle()
{
try
{
DataSet oDS = new DataSet();
SqlParameter[] oParam = new SqlParameter[1];
oParam[0] = new SqlParameter("@m_RoleID", _smRoleMasterRoleID);
oDS = SqlHelper.ExecuteDataset( DataConnectionString, CommandType.StoredProcedure, "SelectmRoleMaster", oParam);
return oDS;
}
catch (Exception e)
{
ErrorMessage = e.Message;
return null;
}
}如果你觉得有用,请标记为你的答案,否则让我知道…
https://stackoverflow.com/questions/8140327
复制相似问题