使用asp.net获取主键表的radiobutton列表的值到另一个外键表

时间:2021-01-15 10:23:14

I have created two tables in a SQL Server database and a RadioButtonList in an ASP.NET page. 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.

我在SQL Server数据库中创建了两个表,在ASP.NET页面中创建了一个RadioButtonList。在一个表中,我将每个单选按钮的值存储为主键。我希望在单击该单选按钮时,它的主键值存储在外键列中的另一个表中。

Here I am using store procedure in 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:

这里我在MS-SQl中使用存储过程。主键表是性别与外键表是user.In aspx页面我DM dispalying性别作为单选按钮,现在的问题是我怎么能取性别表的主ID和用户table.My代码填写为如下:

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. help out.......

我正在获得radiobutton的值如何获得特定按钮的ID。帮忙.......

1 个解决方案

#1


0  

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之类的事情,并将@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();
    }
}

#1


0  

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之类的事情,并将@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();
    }
}