Asp.Net值插入数据库 [英] Asp.Net value insert into database

查看:68
本文介绍了Asp.Net值插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用复选框在SQL Server 2008数据库中插入值.
所以请为此提供帮助.

i have to insert value in the SQL server 2008 database using checkbox.
so please help me for this.

推荐答案

答案:

The Answer:

<form id="form1" runat="server">
     <asp:checkbox id="chkBox" runat="server" text="Agreed" xmlns:asp="#unknown">
                              oncheckedchanged="chkBox_CheckedChanged" />
</form>
</asp:checkbox>





protected void chkBox_CheckedChanged(object sender, EventArgs e)
    {
        SqlConnection conn = null;

        try
        {
            using (conn=new SqlConnection("YourConnectionString"))
            {
                String strSQL=String.Empty;
                strSQL=String.Format("INSERT Test(Agrement) VALUES({0})",chkBox.Checked);

                SqlCommand cmd=new SqlCommand();
                cmd.Connection=conn;
                cmd.CommandText=strSQL;
                cmd.CommandType=System.Data.CommandType.Text;

                int intResult=cmd.ExecuteNonQuery();
            }

        }
        catch (Exception)
        {

            throw;
        }
        finally
        {
            conn.Close();
            conn=null;
        }
    }



谢谢,

请阅读我最新发布的文章以及Plz的评论或投票.
软件应用程序框架 [



Thanks,

Please read my newly posted article and Plz comments or vote.
A Framework for Software Application[^]


它将帮助您了解更多
在运行时在DataList中显示彩色项目并处理DataListItem CheckBox事件 [ ^ ]
it will help you to know more
Display Colored Items in DataList at runtime and handling the DataListItem CheckBox event [^]


这篇关于Asp.Net值插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆