返回首页

我有3个表:

tb_plane          tb_attributes        tb_as_plane_attributes

plane_id          attribute_id         plane_attribute_id

plane_name        attribute_name       FK_plane_id

                                       FK_attribute_id

                                       value

我想的是平面与属性,并设置每个属性的值。我我填充与所有plane_name的的组合:

{C}
现在,我想从tb_attributes ATTRIBUTE_NAME所有属性来填充一个DataGrid。一coulmn所有ATTRIBUTE_NAME列第二 - 价值。我想我想涉及与飞机的按一下按钮,使关系,并保存到表tb_as_plane_attributes这个属性设定值。不保存在assocation表其余的属性,我不把值。在最后一个按钮的Click事件接受。

我尝试,使这项工作,但我有问题。我尝试实施的DataGrid:
private void PopulateGridByAttributes()

        {

            try

            {

            string ConnectionString = conSettings.ConnectionString;

 

                DataSet dataSet = new DataSet();

                using (SqlConnection connection = new SqlConnection(ConnectionString))

                {

                    connection.Open();

                    using (SqlCommand command = new SqlCommand())

                    {

                        command.Connection = connection;

                        using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))

                        {

                            command.CommandText = ("SELECT attribute_id, attribute_name FROM tb_attributes");

                            dataAdapter.Fill(dataSet, "tb_attributes");

 

                            GrdAllAttributes.Columns.Add("attribute_name", "name of attribute");

                            GrdAllAttributes.Columns.Add("dd", "Value");

                            int row = dataSet.Tables["tb_attributes"].Rows.Count - 1;

                            for (int r = 0; r <= row; r++)

                            {

                                GrdAllAttributes.Rows.Add();

                                GrdAllAttributes.Rows[r].Cells[0].Value = dataSet.Tables["tb_Atributtes"].Rows[r].ItemArray[1];   //attribute_name

                            }

                        }

                    }

                    connection.Close();

                }

            }

            catch (System.Data.SqlClient.SqlException ex)

            {

                string str;

                str = "Source:" + ex.Source;

                str += "\n" + "Message:" + ex.Message;

                MessageBox.Show(str, "Database Exception");

            }

            catch (System.Exception ex)

            {

                string str;

                str = "Source:" + ex.Source;

                str += "\n" + "Message:" + ex.Message;

                MessageBox.Show(str, "Generic Exception");

            }

            finally

            {

            }

        }
| carlito_brigante:DanHodgson88 | |我想说,你需要看看内部联接。当试图从多个表,你需要使用内部的数据连接,以确保正确的数据检索。采取看看这个链接:



希望这有助于

回答

评论会员: 时间:2