0

以前のドロップダウンリストの値に基づいて値を取得する必要があります。しかし、依存しているテーブルが3つあるため、混乱しています。

dbo.Client
ClientID(PK) | ClientName

dbo.Client_POC_Bridge
ClientID(FK) | POCID (FK)

dbo.PointOfContact
POCID(PK) | FName | LName

2つのドロップダウンリストがあります:

DropDownList1:CLientのテーブル情報をバインドしました

DropDownList2: I need FName and Lname from dbo.PointOfContact

これまでのところ、これはコードですが、機能していません。

protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
        {

            DropDownList6.Items.Clear();
            DropDownList6.Items.Add(new ListItem("--Select Point Of Contact--", ""));
            DropDownList6.AppendDataBoundItems = true;

            String var = System.Configuration.ConfigurationManager.ConnectionStrings["KKSTechConnectionString"].ConnectionString;

            String strQuery = "select FirstName, POCID from PointOfCContact " +
                               "where ClientID=@ClientID";
            SqlConnection con = new SqlConnection(var);
            SqlCommand cmd = new SqlCommand();
            cmd.Parameters.AddWithValue("@ClientID",
                DropDownList3.SelectedItem.Value);
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = strQuery;
            cmd.Connection = con;
            try
            {
                con.Open();
                DropDownList6.DataSource = cmd.ExecuteReader();
                DropDownList6.DataTextField = "FirstName";
                DropDownList6.DataValueField = "POCID";
                DropDownList6.DataBind();
                if (DropDownList6.Items.Count > 1)
                {
                    DropDownList6.Enabled = true;
                }
                else
                {
                    DropDownList6.Enabled = false;

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
                con.Dispose();
            }

        }
4

1 に答える 1

0

次の行を変更します...内部結合を使用して値を取得します...

String strQuery ="select pof.FirstName, pof.POCID from PointOfCContact pof Inner Join Client_POC_Bridge cpb On pof.POCID =cpb.POCID where cpb.ClientID=@ClientID";
于 2012-08-14T09:22:41.170 に答える