SQL Server で行を更新する際に問題に直面しています
ストアド プロシージャを使用して、グリッドから SQL Server データベースのテーブルに列を更新する場合、onclick
(更新用の) ボタンに問題があります。イベントを呼び出しRowUpdating
ます...問題は、そのイベントへのアクセスがないことです...最初の行にMsgBoxを配置したため..何も起こりませんでした
これはコードです:
asp .net コード:
<asp:GridView ID="DossierGV" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
DataKeyNames="ID_Dossier" onrowupdating="DossierGV_RowUpdating" >
<Columns>
<%-- <asp:BoundField DataField="Nom_Giac" HeaderText="Nom_Giac"
SortExpression="Nom_Giac" />--%>
<asp:CommandField ShowEditButton="True" UpdateText="Modifier "></asp:CommandField>
<asp:CommandField ShowSelectButton="True" />
<asp:TemplateField HeaderText="ID_Dossier" SortExpression="ID_Dossier">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ID_Dossier") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ID_Dossier") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID_Entreprise" SortExpression="ID_Entreprise">
<EditItemTemplate>
<asp:Label ID="ID_Entrepriselbl_Edit" runat="server" Text='<%# Bind("ID_Entreprise") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="ID_Entrepriselbl_Item" runat="server" Text='<%# Bind("ID_Entreprise") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
..... (lots more <asp:TemplateField) ..........
</Columns>
<SelectedRowStyle BackColor="#F2E488" Font-Bold="True" />
これはサーバーコードです:
Imports System.Data.SqlClient
Imports System.Data
Imports System.Configuration
Partial Class GIAC_Gestion_des_dossiers_Les_Dossiers_Finance
Inherits System.Web.UI.Page
Dim sqlcon As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("OfficeConnectionString").ConnectionString)
Dim sqlcmd As SqlCommand
Dim da As SqlDataAdapter
Dim dt As DataTable = New DataTable
Dim dt1 As DataTable = New DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
RecherhcerComboBox.SelectedValue = RecherhcerComboBox.Items(0).Value
If Not Page.IsPostBack Then
GridData()
End If
End Sub
Private Sub GridData()
sqlcmd = New SqlCommand("DossierPF", sqlcon)
sqlcon.Open()
sqlcmd.CommandType = CommandType.StoredProcedure
sqlcmd.Parameters.Add("@nom", SqlDbType.VarChar).Value = Session("Nom_GIAC")
da = New SqlDataAdapter(sqlcmd)
dt.Clear()
da.Fill(dt)
If (dt.Rows.Count > 0) Then
DossierGV.DataSource = dt
DossierGV.DataBind()
End If
End Sub
Protected Sub DossierGV_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DossierGV.SelectedIndexChanged
GridData()
End Sub
Protected Sub DossierGV_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles DossierGV.PageIndexChanging
DossierGV.EditIndex = -1
DossierGV.SelectedIndex = -1
DossierGV.PageIndex = e.NewPageIndex
GridData()
End Sub
Protected Sub DossierGV_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles DossierGV.RowCancelingEdit
DossierGV.EditIndex = -1
GridData()
End Sub
Protected Sub DossierGV_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles DossierGV.RowEditing
DossierGV.EditIndex = e.NewEditIndex
GridData()
End Sub
Protected Sub DossierGV_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles DossierGV.RowUpdating
MsgBox("walo")
Dim row As GridViewRow = DossierGV.Rows(e.RowIndex)
Dim ID_Dossier As Integer = DossierGV.DataKeys(e.RowIndex).Value
Dim Montant_Demander As TextBox = CType(row.FindControl("Montant_DemanderTXT"), TextBox)
Dim Duree As TextBox = CType(row.FindControl("DureeTXT"), TextBox)
Dim Date_Debut As TextBox = CType(row.FindControl("Date_DebutTXT"), TextBox)
Dim Date_Fin As TextBox = CType(row.FindControl("Date_FinTXT"), TextBox)
sqlcmd = New SqlCommand("UPDATE_DOSSIER", sqlcon)
DossierGV.EditIndex = -1
sqlcon.Open()
sqlcmd.CommandType = CommandType.StoredProcedure
sqlcmd.Parameters.Add("@ID_DOSSIER", SqlDbType.Int).Value = ID_Dossier
sqlcmd.Parameters.Add("@Montant_Demander", SqlDbType.Int).Value = Convert.ToInt64(Montant_Demander.Text)
sqlcmd.Parameters.Add("@@Duree", SqlDbType.Int).Value = Convert.ToInt64(Duree.Text)
sqlcmd.Parameters.Add("@Date_Debut", SqlDbType.Int).Value = Convert.ToDateTime(Date_Debut.Text)
sqlcmd.Parameters.Add("@Date_Fin", SqlDbType.Int).Value = Convert.ToDateTime(Date_Fin.Text)
MsgBox(ID_Dossier & " , " & Montant_Demander.Text & " , " & Duree.Text & " , " & Date_Debut.Text & " , " & Date_Fin.Text)
sqlcmd.ExecuteNonQuery()
sqlcon.Close()
GridData()
End Sub
End Class
ストアド プロシージャ:
CREATE PROCEDURE UPDATE_DOSSIER
@ID_DOSSIER integer,
@Montant_Demander integer,
@Duree integer,
@Date_Debut datetime,
@Date_Fin datetime
AS
BEGIN
update dbo.Dossier
set Montant_Demander = @Montant_Demander,
Duree = @Duree,
Date_Debut = @Date_Debut,
Date_Fin = @Date_Fin
where
ID_Dossier = @ID_DOSSIER
END
exec UPDATE_DOSSIER 1,400,5,'2007-01-11 00:00:00.000','2012-01-11 00:00:00.000'