编辑网格视图后无法更新对数据库的更改。没有抛出任何错误,但数据库中的 table 中的更改未更新
Unable to update changes to database after editing the gridview. There are no errors thrown, but changes are not updated in table in database
网络配置
<add name="MyConnection" connectionString="Data Source=HABIBDEA-PC;Initial Catalog=kopma;Persist Security Info=True;User ID=sa;Password=ilovedea1" />
<add name="kopmaConnectionString" connectionString="Data Source=HABIBDEA-PC;Initial Catalog=kopma;User ID=sa;Password=ilovedea1"
providerName="System.Data.SqlClient" />
<add name="kopmaConnectionString2" connectionString="Data Source=HABIBDEA-PC;Initial Catalog=kopma;Persist Security Info=True;User ID=sa;Password=ilovedea1"
providerName="System.Data.SqlClient" />
1.there 是我要更新的代码。
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox nim = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtnime");
TextBox status = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtstat");
con.Open();
SqlCommand cmd = new SqlCommand("update datauser set STATUSANGGOTA=@STATUSANGGOTA where NIM=@NIM", con);
cmd.Parameters.AddWithValue("@STATUSANGGOTA",status.Text.ToString());
cmd.Parameters.AddWithValue("@NIM", nim.Text.ToString());
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
gvbind();
}
2.this 我的连接字符串
public partial class UserAktif : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ToString());
String s = "AKTIF";
protected void Page_Load(object sender, EventArgs e)
{
gvbind();
}
我的aspx代码
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="NIM" CssClass="table table-striped table-bordered bootstrap-datatable datatable responsive" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowEditing="GridView1_RowEditing" AllowPaging="True" PageSize="5" OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="NIM">
<ItemTemplate>
<asp:Label ID="lblnim" runat="server" Text='<%# Eval("NIM") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtnime" runat="server" Text='<%# Eval("NIM")%>' Enabled="false"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="lblstat" runat="server" Text='<%# Eval("STATUSANGGOTA") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtstat" runat="server" Text='<%# Eval("STATUSANGGOTA") %>' >
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnedit" runat="server" CommandName="Edit" CssClass="btn btn-info">Edit</asp:LinkButton><br />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" CssClass="btn btn-success">Update</asp:LinkButton>
<br />
<asp:LinkButton ID="btncancel" runat="server" CommandName="Cancel" CssClass="btn btn-danger">Cancel</asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
可以帮我吗?
如果我单击更新,没有错误,但数据库和 gridview、tolong bisa gaa、kerjaan KP inih 没有变化 -.-
最后,我使用了默认的 gridview 更新命令
我用这个,完美的工作^^
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:kopmaConnectionString %>" SelectCommand="SELECT [NIM], [STATUSANGGOTA] FROM [datauser] WHERE ([STATUSANGGOTA] = @STATUSANGGOTA)"
UpdateCommand="UPDATE datauser SET [STATUSANGGOTA]=@STATUSANGGOTA WHERE [NIM]=@NIM">
<SelectParameters>
<asp:Parameter DefaultValue="AKTIF" Name="STATUSANGGOTA" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
对我来说很好
网络配置
<add name="MyConnection" connectionString="Data Source=HABIBDEA-PC;Initial Catalog=kopma;Persist Security Info=True;User ID=sa;Password=ilovedea1" />
<add name="kopmaConnectionString" connectionString="Data Source=HABIBDEA-PC;Initial Catalog=kopma;User ID=sa;Password=ilovedea1"
providerName="System.Data.SqlClient" />
<add name="kopmaConnectionString2" connectionString="Data Source=HABIBDEA-PC;Initial Catalog=kopma;Persist Security Info=True;User ID=sa;Password=ilovedea1"
providerName="System.Data.SqlClient" />
1.there 是我要更新的代码。
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox nim = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtnime");
TextBox status = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtstat");
con.Open();
SqlCommand cmd = new SqlCommand("update datauser set STATUSANGGOTA=@STATUSANGGOTA where NIM=@NIM", con);
cmd.Parameters.AddWithValue("@STATUSANGGOTA",status.Text.ToString());
cmd.Parameters.AddWithValue("@NIM", nim.Text.ToString());
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
gvbind();
}
2.this 我的连接字符串
public partial class UserAktif : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnection"].ToString());
String s = "AKTIF";
protected void Page_Load(object sender, EventArgs e)
{
gvbind();
}
我的aspx代码
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="NIM" CssClass="table table-striped table-bordered bootstrap-datatable datatable responsive" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowEditing="GridView1_RowEditing" AllowPaging="True" PageSize="5" OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:TemplateField HeaderText="NIM">
<ItemTemplate>
<asp:Label ID="lblnim" runat="server" Text='<%# Eval("NIM") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtnime" runat="server" Text='<%# Eval("NIM")%>' Enabled="false"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="lblstat" runat="server" Text='<%# Eval("STATUSANGGOTA") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtstat" runat="server" Text='<%# Eval("STATUSANGGOTA") %>' >
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnedit" runat="server" CommandName="Edit" CssClass="btn btn-info">Edit</asp:LinkButton><br />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" CssClass="btn btn-success">Update</asp:LinkButton>
<br />
<asp:LinkButton ID="btncancel" runat="server" CommandName="Cancel" CssClass="btn btn-danger">Cancel</asp:LinkButton>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
可以帮我吗? 如果我单击更新,没有错误,但数据库和 gridview、tolong bisa gaa、kerjaan KP inih 没有变化 -.-
最后,我使用了默认的 gridview 更新命令 我用这个,完美的工作^^
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:kopmaConnectionString %>" SelectCommand="SELECT [NIM], [STATUSANGGOTA] FROM [datauser] WHERE ([STATUSANGGOTA] = @STATUSANGGOTA)"
UpdateCommand="UPDATE datauser SET [STATUSANGGOTA]=@STATUSANGGOTA WHERE [NIM]=@NIM">
<SelectParameters>
<asp:Parameter DefaultValue="AKTIF" Name="STATUSANGGOTA" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
对我来说很好