且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有主键的数据库表上执行GridView更新

更新时间:2023-11-24 13:31:28

ConnectionStrings:gsiadmin%> ProviderName = <%
ConnectionStrings:gsiadmin %>" ProviderName="<%


ConnectionStrings:gsiadmin.ProviderName%>
SelectCommand = SELECT * FROM GSI_SWIFT_AUDIT
UpdateCommand = UPDATE GSI_SWIFT_AUDIT SET [ACTION_IND] = @ ACTION_IND,[ACTION_DATE] = @ ACTION_DATE,[USERNAME] = @ USERNAME WHERE([MSG_ID] = @ MSG_ID)
FilterExpression = MSG_ID = {0} >
< FilterParameters>
< as p:ControlParameter Name = txtsearchMSGID ControlID = txtsearchMSGID PropertyName = Text />
< / FilterParameters >
< UpdateParameters>
< asp:参数名称= MSG_ID Type = 十进制 />
< asp:参数名称= ACTION_IND Type = String />
< asp:参数名称= ACTION_DATE Type = DateTime />
< asp:参数名称= USERNAME Type = String />
< / UpdateParameters >
< InsertParameters>
< asp:参数名称= MSG_ID Type = 十进制 />
< asp:参数名称= ACTION_IND Type = String />
< asp:参数名称= ACTION_DATE Type = DateTime />
< asp:参数名称= USERNAME Type = String />
< / InsertParameters >
< / asp:SqlDataSource >
< / ContentTemplate >
<触发器>
< asp:AsyncPostBackTrigger ControlID = txtsearchMSGID EventName = TextChanged />
< / 触发器 >
< / asp:UpdatePanel >
ConnectionStrings:gsiadmin.ProviderName %>" SelectCommand="SELECT * FROM GSI_SWIFT_AUDIT" UpdateCommand="UPDATE GSI_SWIFT_AUDIT SET [ACTION_IND]=@ACTION_IND, [ACTION_DATE]=@ACTION_DATE, [USERNAME]=@USERNAME WHERE ([MSG_ID]=@MSG_ID)" FilterExpression="MSG_ID = {0}"> <FilterParameters> <asp:ControlParameter Name="txtsearchMSGID" ControlID="txtsearchMSGID" PropertyName="Text" /> </FilterParameters> <UpdateParameters> <asp:Parameter Name="MSG_ID" Type="Decimal" /> <asp:Parameter Name="ACTION_IND" Type="String" /> <asp:Parameter Name="ACTION_DATE" Type="DateTime" /> <asp:Parameter Name="USERNAME" Type="String" /> </UpdateParameters> <InsertParameters> <asp:Parameter Name="MSG_ID" Type="Decimal" /> <asp:Parameter Name="ACTION_IND" Type="String" /> <asp:Parameter Name="ACTION_DATE" Type="DateTime" /> <asp:Parameter Name="USERNAME" Type="String" /> </InsertParameters> </asp:SqlDataSource> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="txtsearchMSGID" EventName="TextChanged" /> </Triggers> </asp:UpdatePanel>





.aspx.cs



.aspx.cs

public partial class Approve_Swift : System.Web.UI.Page
{
    string MSGID = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        txtsearchMSGID.Attributes.Add("onkeyup", "setTimeout('__doPostBack(\\'" + txtsearchMSGID.ClientID.Replace("_", "


)+ \\',\\'\\')',0););
if (!IsPostBack)
{
GridView1.DataBind();
}
}

受保护 void Clear_Click( object sender,EventArgs e)
{
txtsearchMSGID.Text = 跨度>;
}



受保护 void txtsearchMSGID_TextChanged( object sender,EventArgs e)
{
MSGID = txtsearchMSGID.Text;

}

protected void GridView1_RowUpdated( Object
sender,GridViewUpdatedEventArgs e)
{

// 指示更新操作是否成功。
if (e.Exception == null
{
Message.Text = 行更新成功跨度>。
}
else
{
e.ExceptionHandled = true 跨度>;
Message.Text = 尝试更新行时发生错误。;
}

}

受保护 void GridView1_RowCancelingEdit( Object sender,GridViewCancelEditEventArgs e)
{

// 更新操作已取消。清除消息标签。
Message.Text = ;

}

受保护 void GridView1_RowEditing( Object
sender,GridViewEditEventArgs e)
{
// GridView控件正在进入编辑模式。清除消息标签。
GridView1.EditIndex = e.NewEditIndex;
DataBind();
Message.Text = ;
}
}
") + "\\',\\'\\')', 0);"); if (!IsPostBack) { GridView1.DataBind(); } } protected void Clear_Click(object sender, EventArgs e) { txtsearchMSGID.Text = ""; } protected void txtsearchMSGID_TextChanged(object sender, EventArgs e) { MSGID = txtsearchMSGID.Text; } protected void GridView1_RowUpdated(Object sender, GridViewUpdatedEventArgs e) { // Indicate whether the update operation succeeded. if (e.Exception == null) { Message.Text = "Row updated successfully."; } else { e.ExceptionHandled = true; Message.Text = "An error occurred while attempting to update the row."; } } protected void GridView1_RowCancelingEdit(Object sender, GridViewCancelEditEventArgs e) { // The update operation was canceled. Clear the message label. Message.Text = ""; } protected void GridView1_RowEditing(Object sender, GridViewEditEventArgs e) { // The GridView control is entering edit mode. Clear the message label. GridView1.EditIndex = e.NewEditIndex; DataBind(); Message.Text = ""; } }