关于如何使用交易有很多很多问题.我想知道的是何时?在什么情况下?什么类型的查询?Try-Catch块可以代替吗?等等...
我设计了一个包含~20个表和~20个存储过程的数据库.目前我的SP中没有一个使用事务,但整个过程中有许多Try-Catch块.原因是因为每当我试图将它们包装在一个事务中时,SP就会停止运行,我最终会丢失数据并且比我使用Trans更糟糕.
再说......
这是我为重命名产品而写的一个小样本SP:
CREATE PROCEDURE spRenameProduct
@pKey int = NULL,
@pName varchar(50)
AS
BEGIN
BEGIN TRY
IF LTRIM(RTRIM(@pName)) = '' SET @pName = NULL
IF NOT @pKey IS NULL AND NOT @pName IS NULL BEGIN
declare @pKeyExisting int = (select MIN(ID) from rProduct where Product like @pName and not ID = @pKey)
IF @pKeyExisting is null BEGIN
update rProduct set IsValid = 1, Product = @pName where ID = @pKey
END ELSE BEGIN
update Request …Run Code Online (Sandbox Code Playgroud) 这个问题一直困扰着我......
在本地Intranet环境中,如果我们想要使用模拟我们的Windows域用户,我们注定要在我们的应用程序池中使用"经典"管道模式,或者是否有一种新的方式来声明性地"运行"它们(可以这么说) )?
我的目标是在我的Intranet上对本地Web应用程序使用Windows身份验证,以便用户可以在其活动目录帐户下进行身份验证和运行应用程序(原则).每次我尝试这个(当然使用NetworkService身份),我都会收到此错误:

谢谢!;)
impersonation windows-authentication integrated-pipeline-mode iis-7.5 windows-server-2008-r2
问这么简单的问题我觉得有些愚蠢,但我似乎无法找到答案.我是ASP.NET(C#)的新手,但我正在学习构建一组显示报告的简单网页.我有一个代表公司名称的变量.我需要在网页上的多个位置输出此变量.我发现输出变量的唯一方法是:
company_name.Text = "Acme Windows";
Run Code Online (Sandbox Code Playgroud)
然后
<asp:literal id="company_name" runat="server" />
Run Code Online (Sandbox Code Playgroud)
我的问题是我想在页面的多个地方使用company_name.我是否真的必须创建一个单独的变量,每次在页面上放置相同的值?如果我只是将上面的XML代码复制到我想要显示变量的所有位置,那么它显然会产生编译错误,因为已经定义了该ID.
我觉得我错过了一些非常明显的东西.
有人可以为我填写空白,包括使用的简短描述,也许还有代码片段?我特别清楚前两名,但最后一点尤其朦胧:
例如,我一直看到这样的东西,但仍然不太确定括号意味着什么......
<TemplateContainer(GetType(TemplateItem))> _
Public Property MessageTemplate As ITemplate
Run Code Online (Sandbox Code Playgroud) 我得到以下例外:"每个配置文件只能出现一次.请参阅帮助主题以了解异常."
我的配置文件如下所示:
<configSections>
<sectionGroup name="point.System">
<section name="singleInstanceCache"
type="xyz.Point.System.Configuration.SingleInstanceCache, Point.System" />
</sectionGroup>
<sectionGroup name="point.Services">
<sectionGroup name="xServices" type="xyz.Point.Messaging.PointServiceConfiguration.PointServices, Barcap.FIA.Point.Messaging">
<section name="xService"
type="xyz.Point.Messaging.PointServiceConfiguration.PointService, Barcap.FIA.Point.Messaging" />
</sectionGroup>
</sectionGroup>
</configSections>
<point.Services>
<xServices>
<xService name="Service1" type="IService" >
<endpoints>
<endpoint aliasName="incoming" endpointName="Subscriber"/>
<endpoint aliasName="outgoing" endpointName="Publisher"/>
</endpoints>
</xService>
<xService name="BlobService" type="IPortfolioService" >
<endpoints>
<endpoint aliasName="incoming" endpointName="Subscriber"/>
<endpoint aliasName="outgoing" endpointName="Publisher"/>
</endpoints>
</xService>
</xServices>
</point.Services>
Run Code Online (Sandbox Code Playgroud)
这是我加载它的代码:
public class PointServices : ConfigurationSection
{
public static PointServices Get()
{
var t = (PointServices)ConfigurationManager.GetSection("point.Services/xServices");
return null;
}
//<summary>
//Declares a collection …Run Code Online (Sandbox Code Playgroud) 我在这里敲我的头.我觉得很愚蠢,因为我确定我以前做过这样的事情,但不能为我的生活记住如何.其中一天我猜>.<
说我有以下数据:--->和一个返回此的查询:--->但我想要这个:
ID FirstID ID FirstID ID FirstID
-- ------- -- ------- -- -------
1 1 1 1 7 1
2 1 3 3 3 3
3 3 4 4 6 4
4 4 5 5 5 5
5 5
6 4
7 1
Run Code Online (Sandbox Code Playgroud)
请注意,我的查询返回ID = FirstID的记录,但我希望它返回唯一FirstID的每个子集的Max(ID).听起来很简单吧?这就是我的想法,但我一直在追回记录#7.这是我的查询(返回上面第二块图的那个)和一些测试代码,让您的生活更轻松.我需要这个给我最右边的块结果.应该注意,这是一个自连接表,其中FirstID是ID的外键.谢谢 :)
declare @MyTable table (ID int, FirstID int)
insert into @MyTable values (1,1),(2,1),(3,3),(4,4),(5,5),(6,4),(7,1)
select ID, FirstID
from @MyTable
where ID = FirstID
Run Code Online (Sandbox Code Playgroud) 我正在使用listview控件.默认情况下,我使用编辑按钮显示itemtemplate.按下编辑按钮后,列表视图将切换到edititemtemplate.我需要根据正在编辑的项目填充edititemtemplate中的一个控件 - 我尝试在ItemEditing事件中访问控件(通过FindControl)(以及几乎所有其他事件),但是控件只是'似乎存在.我可以在itemtemplate ok中访问控件,但不能访问edititemtemplate.
任何人都可以告诉我如何访问listview的edititemtemplate中的控件,以及我应该从哪个事件中执行此操作?
编辑 我正试图使用这个访问控件:
protected void UnitsLV_ItemEditing(object sender, ListViewEditEventArgs e)
{
ListViewItem item = UnitsLV.Items[e.NewEditIndex];
ListBox tempLB = (ListBox)e.item.FindControl("ListBox3");
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过ItemDataBound和ItemCreated.
listview声明是:
<asp:Content ID="Content1" ContentPlaceHolderID="ColumnA" runat="server">
<asp:Panel ID="Panel1" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="SummaryPnl" runat="server">
<asp:ListView ID="UnitsLV" runat="server" DataSourceID="DataLDS" DataKeyNames="u_uid"
InsertItemPosition="LastItem" OnItemInserting="UnitsLV_ItemInserting" OnItemDataBound="UnitsLV_ItemDataBound"
OnItemCreated="UnitsLV_ItemCreated" onitemediting="UnitsLV_ItemEditing">
<ItemTemplate>
<tr class="rowA">
<td>
<asp:Label runat="server" ID="UnitIDLbl" Text='<%# Eval("u_uid")%>'></asp:Label>
</td>
<td>
<%# Eval("u_Title")%>
</td>
<td>
<asp:LinkButton ID="EditBtn" runat="server" CommandName="Edit" CommandArgument='<%#Eval("u_uid") %>'
Text="Edit" />
</td>
<td>
<asp:LinkButton ID="DeleteBtn" runat="server" CommandName="Delete" CommandArgument='<%#Eval("u_uid") %>' …Run Code Online (Sandbox Code Playgroud) 我花了一个多小时试图解决这个问题,我很绝望.我试图访问从ASP.NET控件创建的DOM中的节点.我正在使用完全相同的ID,我可以看到它们在页面呈现后查看HTML源代码时匹配.这是我的[MODIFIED根据建议,但仍然没有工作]代码:
ASP.NET标头
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
$(document).ready(
var el = document.getElementById('<%= txtBox.ClientID %>');
el.onchange = alert('test!!');
)
</script>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
ASP.NET Body
<asp:TextBox ID="txtBox" runat="server"></asp:TextBox>
Run Code Online (Sandbox Code Playgroud)
从上面得到的Javascript和HTML
<script type="text/javascript">
$(document).ready(
var el = document.getElementById('MainContent_txtBox');
el.onchange = alert('test!!');
)
</script>
...
<textarea name="ctl00$MainContent$txtBox" id="MainContent_txtBox"></textarea>
Run Code Online (Sandbox Code Playgroud)
我只能假设脚本在控件ID解析之前加载,但是当我使用Chrome的"Inspect Element"功能查看时间轴时,似乎并非如此.当我创建一个常规的textarea框来测试和实现相同的代码(当然是不同的id)时,会触发警告框.
我到底在这里错过了什么?这让我发疯了.<
编辑:有效的Wierd代码,但仅限于初始页面加载; 点燃onload而不是onchange.甚至jQuery说.ready已经显然无法正常工作.啊!!
$(document).ready(function() {
document.getElementById('<%= txtBox.ClientID %>').onchange = alert('WORKING!');
})
Run Code Online (Sandbox Code Playgroud) 我花了最近两天试图将一些血腥数据导出到Excel.经过大量研究后,我确定最好和最常用的方法是使用HttpResponse标题,如下面的代码所示.在调试模式中经过无数次之后,我已经确认数据实际存在,并且按照我想要的方式进行过滤和排序.但是,它不会作为Excel文件下载,也不会做任何事情.
我怀疑这可能与我UpdatePanel或可能ImageButton没有正确回复有关,但我不确定.我究竟做错了什么?请帮我调试这个问题.我会永远感激.谢谢.:)
标记
<asp:UpdatePanel ID="statusUpdatePanel" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnExportXLS" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="10"
AllowSorting="True" DataSourceID="GridView1SDS" DataKeyNames="ID">
</asp:GridView>
<span><asp:ImageButton ID="btnExportXLS" runat="server" /></span>
</ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
代码隐藏
Protected Sub ExportToExcel() Handles btnExportXLS.Click
Dim dt As New DataTable()
Dim da As New SqlDataAdapter(SelectCommand, ConnectionString)
da.Fill(dt)
Dim gv As New GridView()
gv.DataSource = dt
gv.DataBind()
Dim sw As New IO.StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(sw)
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment;filename=Report.xls")
Response.Charset = String.Empty …Run Code Online (Sandbox Code Playgroud) asp.net ×4
vb.net ×2
app-config ×1
c# ×1
controls ×1
dom ×1
gridview ×1
iis-7.5 ×1
javascript ×1
listview ×1
max ×1
punctuation ×1
reusability ×1
sql-server ×1
subset ×1
syntax ×1
t-sql ×1
templates ×1
transactions ×1
try-catch ×1
updatepanel ×1