在插入查询中需要帮助 [英] Need help in insert query

查看:73
本文介绍了在插入查询中需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我的页面中有3个复选框以及其他控件..

请告诉我如何改正用于插入用户选中的复选框值的代码。



谢谢

Hi all

I have 3 check box in my page along with other controls..
please tell me how to right the code to insert the value of check box selected by the user.

Thank you

推荐答案

hi snehasis ,



如果您使用的是sql server,那么您可以尝试以下代码。



Hi snehasis,

If you are using sql server then you can try the following code.

INSERT INTO (TableName) (Column Names) VALUES (@checkBox1, @checkBox2, @checkBox3)





这里@ checkBox1, @ checkBox2,@ checkBox3是insert语句的参数。



对于C#代码,您可以尝试以下代码。





Here @checkBox1, @checkBox2, @checkBox3 are the parameters to the insert statement.

For C# Code you can try the following code.

foreach (DataListItem item in Security1.Items) {
        CheckBox CheckBox1 = (CheckBox)item.FindControl("CheckBox1");

        if (CheckBox1.Checked) {
            HiddenField h = (HiddenField)item.FindControl("FeaID");
            string add = "Insert into Carfeature (RecID,FeatureID) values ((select Max(RecID) from record),@FeatureID)";
            cmd[k] = new SqlCommand();
            cmd[k].CommandType = CommandType.Text;
            cmd[k].Parameters.Add("@FeatureID", SqlDbType.Int).Value = h.Value;
            cmd[k].CommandText = add;
            k++;
        }
}





如需参考,请点击以下链接。 插入查询



谢谢



For reference follow the following link. Insert Query

Thanks


插入表名(列名)值(''&checkbox1.checked&'')
insert into table name (column name) values (''" & checkbox1.checked & "'')


这篇关于在插入查询中需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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