| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 626 人关注过本帖
标题:添加代码问题
只看楼主 加入收藏
水晶心
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2010-7-27
结帖率:80%
收藏
已结贴  问题点数:20 回复次数:4 
添加代码问题
想在系统考勤页面添加数据,其中休假分类这个字段是在表:休假表中,和其它字段都在考勤表中,这应该怎么添加啊,

public partial class adminmofiy : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
      

    } protected void  btn_modify_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string str = ConfigurationSettings.AppSettings["dsn"];
            SqlConnection cn = new SqlConnection(str);
            cn.Open();
            string mysql = " insert from kaoqin,xiujia SET kid='" + T_kid.Text + "',uid='" + T_kid.Text + "',uname = '" + T_aname.Text + "', xid='"+Textbox2.text+"',lx='"+Textbox1.text+"')";
            SqlCommand cm = new SqlCommand(mysql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
            Response.Redirect("kqmanage.aspx");

           }
          }

    protected void btn_detele_Click(object sender, EventArgs e)
    {

        if (Page.IsValid)
        {
            string str = ConfigurationSettings.AppSettings["dsn"];
            SqlConnection cn = new SqlConnection(str);
            cn.Open();
            string mysql = "delete kaoqin WHERE (kid = '" + T_kid.Text + "') ";
            SqlCommand cm = new SqlCommand(mysql, cn);
            cm.ExecuteNonQuery();
            cn.Close();
            Response.Redirect("kqmanage.aspx");
        }
    }
不知道代码对不对啊。
<form id="form1" runat="server">
    <div>
        <asp:Table ID="Table1" runat="server" Height="109px" Style="z-index: 100; left: 30px;
            position: absolute; top: 10px" Width="656px">
            <asp:TableRow runat="server">
                <asp:TableCell runat="server"><asp:Label ID="Label1" runat="server" Style="z-index: 102; left: 203px; position: absolute;
            top: 44px" Text="考勤管理系统" Width="216px" Font-Size="20pt"></asp:Label>
            </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow runat="server">
                <asp:TableCell runat="server"><asp:Label ID="Label2" runat="server" Style="z-index: 102; left: 253px; position: absolute;
            top: 80px" Text="-----考勤管理" Width="154px"></asp:Label>
            </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
        &nbsp;&nbsp;
        <asp:Table ID="Table2" runat="server" Height="280px" Style="z-index: 101; left: 24px;
            position: absolute; top: 119px" Width="662px">
            <asp:TableRow runat="server">
                <asp:TableCell runat="server"></asp:TableCell>
            </asp:TableRow>
        </asp:Table>
        <asp:Table ID="Table4" runat="server" Height="312px" Style="z-index: 102; left: 132px;
            position: absolute; top: 122px" Width="545px">
        </asp:Table>
        <asp:TextBox ID="TextBox2" runat="server" Style="z-index: 103; left: 368px; position: absolute;
            top: 123px" Width="75px"></asp:TextBox>
        <asp:Label ID="Label7" runat="server" Height="21px" Style="z-index: 104; left: 318px;
            position: absolute; top: 124px" Text="姓名:" Width="48px"></asp:Label>
        <asp:Button ID="Button1" runat="server" Style="z-index: 105; left: 454px; position: absolute;
            top: 122px" Text="查询" OnClick="Button1_Click" />
        &nbsp;&nbsp;
        <asp:LinkButton ID="LinkButton8" runat="server" Height="24px" Style="z-index: 106;
            left: 526px; position: absolute; top: 127px">添加员工考勤信息</asp:LinkButton>
        <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: 107;
            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>
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        &nbsp;&nbsp;
        <asp:Table ID="Table3" runat="server" Height="368px" Style="z-index: 109; left: 26px;
            position: absolute; top: 125px" Width="112px" HorizontalAlign="Left" GridLines="Horizontal">
            <asp:TableRow runat="server">
                <asp:TableCell runat="server" Height="20px" HorizontalAlign="Center" VerticalAlign="Middle">
                <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="adminmassage.aspx">人员管理信息</asp:LinkButton>
           </asp:TableCell>


休假分类指的就是“事假,出勤啊等。
搜索更多相关主题的帖子: 代码 
2010-08-25 09:53
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:6 
insert from kaoqin,xiujia SET kid='" + T_kid.Text + "',uid='" + T_kid.Text + "',uname = '" + T_aname.Text + "', xid='"+Textbox2.text+"',lx='"+Textbox1.text+"')";
不能这么写的,应该分别像不同的表,插入数据,也就是说,这个语句你应该写成两个
insert into kaoqin(...) values(...)
insert into xiujia(...) values(...)

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2010-08-25 17:25
qingshuiliu
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:17
帖 子:323
专家分:1538
注 册:2009-12-28
收藏
得分:6 
支持楼上
2010-08-25 21:57
水晶心
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2010-7-27
收藏
得分:0 
好的
2010-08-26 14:37
tony_wen
Rank: 2
来 自:江西
等 级:论坛游民
帖 子:34
专家分:44
注 册:2010-8-21
收藏
得分:6 
" insert from kaoqin,xiujia SET kid='" + T_kid.Text + "',uid='" + T_kid.Text + "',uname = '" + T_aname.Text + "', xid='"+Textbox2.text+"',lx='"+Textbox1.text+"')";
标准的写法:
1. insert into ..values(..)或是inert into XXX select * from XXX;
2. update ..set ...
你上面那样写是创新吗?



[ 本帖最后由 tony_wen 于 2010-8-26 17:21 编辑 ]
2010-08-26 17:19
快速回复:添加代码问题
数据加载中...
 
   



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

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