| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1012 人关注过本帖
标题:必须声明变量 '@kid'。
只看楼主 加入收藏
水晶心
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2010-7-27
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:6 
必须声明变量 '@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();
        }

    }
}
数据更新不了怎么回事啊,请各位高手帮忙
搜索更多相关主题的帖子: kid 变量 声明 
2010-08-17 10:08
yukai621
Rank: 2
等 级:论坛游民
威 望:1
帖 子:27
专家分:71
注 册:2010-8-13
收藏
得分:6 
没看明白 你问的是什么
2010-08-17 11:00
NewDeveloper
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:48
专家分:159
注 册:2010-7-2
收藏
得分:6 
你用GridView里面生成搜索语句不是有个参数@kid么
 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">

下面还有很多参数 你都必须指明它们是根据那个值传进去的
            
2010-08-17 12:50
水晶心
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2010-7-27
收藏
得分:0 
怎么写代码啊,我是个菜鸟,对代码不太懂,现在在学习中,请教一下
2010-08-17 15:01
misswang
Rank: 8Rank: 8
来 自:湖北荆州
等 级:贵宾
威 望:15
帖 子:265
专家分:720
注 册:2010-3-11
收藏
得分:6 
你的GridView绑定了两次数据,
程序代码:
 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();

    }

第二次是这样
程序代码:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966" BorderStyle="None"
            BorderWidth="1px" CellPadding="4"
            onpageindexchanging="GridView1_PageIndexChanging" PageSize="5" Style="z-index: 109;
            left: 140px; position: absolute; top: 148px" Width="396px" HorizontalAlign="Left">
            <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
DataSourceID="SqlDataSource1"上面的这个就已经绑定


[ 本帖最后由 misswang 于 2010-8-17 16:59 编辑 ]

misswp2010@
wangping103@
2010-08-17 16:58
NewDeveloper
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:48
专家分:159
注 册:2010-7-2
收藏
得分:0 
按照楼上说的可以把DataSourceID="SqlDataSource1"这个去掉 用代码绑定就没什么问题了
2010-08-17 18:12
快速回复:必须声明变量 '@kid'。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033408 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved