简体   繁体   English

使用asp.net将主键表的单选按钮列表的值获取到另一个外键表

[英]fetch values of radiobutton list of primary key table to another foreign key table using asp.net

I have created two tables in a SQL Server database and a RadioButtonList in an ASP.NET page. 我在SQL Server数据库中创建了两个表,在ASP.NET页中创建了RadioButtonList。 In one table I have stored values for each radio button as primary key. 在一个表中,我将每个单选按钮的值存储为主键。 I want that on clicking that radio button, its primary key value in stored another table in a foreign key column. 我希望在单击该单选按钮时将其主键值存储在外键列中的另一个表中。

Here I am using store procedure in MS-SQl. 在这里,我正在使用MS-SQl中的存储过程。 primary key table is gender and foreign key table is user.In aspx page i dm dispalying gender as radiobuttons, now the question is how can i fetch primary id of gender table and fill in users table.My code is as below: 主键表是性别,外键表是用户。在aspx页面中,我将性别作为单选按钮而感到沮丧,现在的问题是如何获取性别表的主ID并填写用户表。我的代码如下:

ArrayList arSample = new ArrayList();
Object[] n_gender_id = new Object[3] { "@intGender", "Int", (rbtngender.SelectedValue != "") ? rbtngender.SelectedValue : "" };

I am getting values of radiobutton how get ids of particular button. 我正在获取radiobutton的值,如何获取特定按钮的ID。 help out....... 帮帮忙.......

It sounds like you want to do something like SELECT [Id] FROM [user] WHERE [gender] = @intGender and set the value of @intGender to be the selected radio button value. 听起来您想执行类似SELECT [Id] FROM [user] WHERE [gender] = @intGender并将SELECT [Id] FROM [user] WHERE [gender] = @intGender的值设置为选定的单选按钮值的操作。

Since the parameter you've shown appears to be an integer, I'd probably start with something like: 由于您显示的参数似乎是整数,因此我可能会以类似以下内容开始:

var arSample = new ArrayList();
int gender;
if (!int.TryParse(rbtngender.SelectedValue, out gender)) return;

using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionStringNameFromWeb.Config"].ConnectionString))
{
    using (var cmd = new SqlCommand("storedProcName", conn))
    {
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@intGender", gender);

        conn.Open();
        using (SqlDataReader dr = cmd.ExecuteReader())
        {
            while (dr.Read())
            {
                // process each row from the data reader...
                arSample.Add(dr["Id"]);
            }
        }
        conn.Close();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET Identity UserID主键是自定义表中的外键和主键 - ASP.NET Identity UserID primary key to be foreign key and primary key in your custom table 在ASP.NET中使用主键插入外键 - Inserting Foreign key using primary key in asp.net 使用 ASP.NET MVC 为没有主键的表创建复选框列表 - Creating a list of checkboxes using ASP.NET MVC for a table without a primary key 使用LINQtoSQL从ASP.NET MVC中的外键表中检索项目和值 - Retrieving Items and values from Foreign Key Table in ASP.NET MVC using LINQtoSQL 如何使用ASP.NET MVC中该表的另一列获取外键表中的记录ID? - How do I get the id of record in foreign key table using another column in that table in ASP.NET MVC? AspNetUsers的主键作为另一个表的外来 - Primary key of AspNetUsers as foreign of another table ASP.NET MVC4表,其中一列是主键 - ASP.NET MVC4 Table with one column that is the primary key 如何在ASP.NET MVC中使用实体框架在父表中创建外键并将其分配给子表 - How to create the foreign key in the parent table and assign it to the child table using entity framework in asp.net mvc 首先在代码中在ASP.NET MVC中的表中添加外键 - Add Foreign Key in Table in ASP.NET MVC in code first Asp.net MVC导出表到Excel | 外键显示 - Asp.net MVC Export Table to Excel | Foreign Key Display
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM