必须声明变量 '@kid'。
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" CellPadding="4" DataSourceID="SqlDataSource1"
onpageindexchanging="GridView1_PageIndexChanging" PageSize="5" Style="z-index: 109;
left: 140px; position: absolute; top: 148px" Width="396px" HorizontalAlign="Left">
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<Columns>
<asp:BoundField DataField="kid" HeaderText="考勤编号" ReadOnly="True" SortExpression="kid" />
<asp:BoundField DataField="uid" HeaderText="用户编号" SortExpression="uid" />
<asp:BoundField DataField="uname" HeaderText="用户姓名" SortExpression="uname" />
<asp:BoundField DataField="kqdate" HeaderText="考勤日期" SortExpression="kqdate" />
<asp:BoundField DataField="dgdate" HeaderText="到岗日期" SortExpression="dgdate" />
<asp:BoundField DataField="sj" HeaderText="事假" SortExpression="sj" />
<asp:BoundField DataField="bj" HeaderText="病假" SortExpression="bj" />
<asp:BoundField DataField="gj" HeaderText="公假" SortExpression="gj" />
<asp:BoundField DataField="kg" HeaderText="旷工" SortExpression="kg" />
<asp:BoundField DataField="cq" HeaderText="出勤" SortExpression="cq" />
<asp:BoundField DataField="hj" HeaderText="婚嫁" SortExpression="hj" />
<asp:BoundField DataField="sj1" HeaderText="丧假" SortExpression="sj1" />
<asp:BoundField DataField="gxj" HeaderText="干休假" SortExpression="gxj" />
<asp:BoundField DataField="tqj" HeaderText="探亲假" SortExpression="tqj" />
<asp:BoundField DataField="pc" HeaderText="陪产假" SortExpression="pc" />
<asp:BoundField DataField="cc" HeaderText="出差" SortExpression="cc" />
<asp:BoundField DataField="dx" HeaderText="倒休" SortExpression="dx" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:kqConnectionString %>"
SelectCommand="SELECT [kid], [uid], [uname], [kqdate], [dgdate], [cq], [sj], [bj], [gj], [kg], [hj], [sj1], [gxj], [tqj], [pc], [cc], [dx] FROM [kaoqin]" DeleteCommand="DELETE FROM [kaoqin] WHERE [kid] = @kid" InsertCommand="INSERT INTO [kaoqin] ([kid], [uid], [uname], [kqdate], [dgdate], [cq], [sj], [bj], [gj], [kg], [hj], [sj1], [gxj], [tqj], [pc], [cc], [dx]) VALUES (@kid, @uid, @uname, @kqdate, @dgdate, @cq, @sj, @bj, @gj, @kg, @hj, @sj1, @gxj, @tqj, @pc, @cc, @dx)" UpdateCommand="UPDATE [kaoqin] SET [uid] = @uid, [uname] = @uname, [kqdate] = @kqdate, [dgdate] = @dgdate, [cq] = @cq, [sj] = @sj, [bj] = @bj, [gj] = @gj, [kg] = @kg, [hj] = @hj, [sj1] = @sj1, [gxj] = @gxj, [tqj] = @tqj, [pc] = @pc, [cc] = @cc, [dx] = @dx WHERE [kid] = @kid">
</asp:SqlDataSource>
public partial class kqmanage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindGrid();
}
private void BindGrid()
{
string str = ConfigurationSettings.AppSettings["dsn"];
SqlConnection cn = new SqlConnection(str);
cn.Open();
String mysql = "select * from kaoqin";
SqlDataAdapter da = new SqlDataAdapter(mysql, cn);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataBind();
cn.Close();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
BindGrid();//重新绑定记录
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//GridView gv = (GridView)sender;
//string aa = e.RowIndex.ToString();
//string id = gv.DataKeys[e.RowIndex].ToString();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
BindGrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
}
//当取消时触发
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;
BindGrid();
}
protected void LinkButton8_Click(object sender, EventArgs e)
{
Response.Redirect("kamanageadd.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
int vardid = Convert.ToInt32(txt_kid.Text.ToString());
Response.Redirect("kpmodify.aspx?kid=" + vardid);
}
catch
{
Response.Write("输入的编号不正确");
Response.End();
}
}
}
数据更新不了怎么回事啊,请各位高手帮忙