Click here to Skip to main content
15,797,062 members
Home / Discussions / C#
   

C#

 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 22:40
mvaOriginalGriff26-Jul-23 22:40 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 23:00
Hillymalen26-Jul-23 23:00 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 23:08
mvaOriginalGriff26-Jul-23 23:08 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 23:13
Hillymalen26-Jul-23 23:13 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Ralf Meier26-Jul-23 23:35
professionalRalf Meier26-Jul-23 23:35 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 23:47
mvaOriginalGriff26-Jul-23 23:47 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 23:45
mvaOriginalGriff26-Jul-23 23:45 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen27-Jul-23 0:23
Hillymalen27-Jul-23 0:23 
yes exatly i did this
C#
private string connectionString = "Data Source=DESKTOP-5GRDQ7C\\SQLEXPRESS;Initial Catalog=Orders;Integrated Security=True"; 
        private SqlDataAdapter masterDataAdapter;
        private SqlDataAdapter detailDataAdapter;
        private DataSet dataSet;

        public Form1()
        {
            InitializeComponent();
        }

        
        private void LoadMasterData()
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string query = "SELECT * FROM ordm";
                SqlDataAdapter adapter = new SqlDataAdapter(query, connection);
                DataTable dataTable = new DataTable();
                adapter.Fill(dataTable);

               
                masterDataGridView.DataSource = dataTable;
            }
        }
        private void LoadData()
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
            {
           
                string ordmQuery = "SELECT * FROM ORDM";
                masterDataAdapter = new SqlDataAdapter(ordmQuery, connection);
                masterDataAdapter.Fill(dataSet, "ORDM");

              
                string ordcQuery = "SELECT * FROM ORDC";
                detailDataAdapter = new SqlDataAdapter(ordcQuery, connection);
                detailDataAdapter.Fill(dataSet, "ORDC");
            }

            
            DataColumn parentColumn = dataSet.Tables["ORDM"].Columns["ORD_NO"];
            DataColumn childColumn = dataSet.Tables["ORDC"].Columns["ORD_NO"];
            DataRelation relation = new DataRelation("ORDM_ORDC_Relation", parentColumn, childColumn);
            dataSet.Relations.Add(relation);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            LoadMasterData();
           
            dataSet = new DataSet();
            LoadData();

           
            masterDataGridView.DataSource = dataSet.Tables["ORDM"];

            
            masterDataGridView.SelectionChanged += masterDataGridView_SelectionChanged_1;
        }

        private void masterDataGridView_SelectionChanged_1(object sender, EventArgs e)
        {
           
            if (masterDataGridView.SelectedRows.Count > 0)
            {
              
                string orderNumber = Convert.ToString(masterDataGridView.SelectedRows[0].Cells["ordcol"].Value);

              
                LoadChildData(orderNumber);
            }
        }
            private void LoadChildData(string orderNumber)
            {
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                   
                    string query = $"SELECT * FROM ordc WHERE ord_no = ord_no";
                    SqlDataAdapter adapter = new SqlDataAdapter(query, connection);
                    DataTable dataTable = new DataTable();
                    adapter.Fill(dataTable);

                   
                    childDataGridView.DataSource = dataTable;
                }
            }
    }


modified 27-Jul-23 5:38am.

GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff27-Jul-23 0:40
mvaOriginalGriff27-Jul-23 0:40 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff27-Jul-23 0:47
mvaOriginalGriff27-Jul-23 0:47 
Questionc# Pin
Impana D patel24-Jul-23 1:54
Impana D patel24-Jul-23 1:54 
AnswerRe: c# Pin
Richard Deeming24-Jul-23 2:08
mveRichard Deeming24-Jul-23 2:08 
AnswerRe: c# Pin
Richard MacCutchan24-Jul-23 2:33
mveRichard MacCutchan24-Jul-23 2:33 
AnswerRe: c# Pin
OriginalGriff24-Jul-23 2:55
mvaOriginalGriff24-Jul-23 2:55 
Questionc# Pin
Impana D patel24-Jul-23 0:46
Impana D patel24-Jul-23 0:46 
AnswerRe: c# Pin
Richard MacCutchan24-Jul-23 1:03
mveRichard MacCutchan24-Jul-23 1:03 
QuestionWhat should be the principles of multilayer software design? Pin
farshad valizade 202323-Jul-23 23:00
farshad valizade 202323-Jul-23 23:00 
AnswerRe: What should be the principles of multilayer software design? Pin
Richard Deeming24-Jul-23 0:11
mveRichard Deeming24-Jul-23 0:11 
QuestionMulti-threading Pin
MAW3017-Jul-23 10:52
MAW3017-Jul-23 10:52 
AnswerRe: Multi-threading Pin
Gerry Schmitz17-Jul-23 16:32
mveGerry Schmitz17-Jul-23 16:32 
AnswerRe: Multi-threading Pin
Dave Kreskowiak17-Jul-23 16:53
mveDave Kreskowiak17-Jul-23 16:53 
QuestionParameterized Query Pin
Richard Andrew x6416-Jul-23 9:47
professionalRichard Andrew x6416-Jul-23 9:47 
AnswerRe: Parameterized Query Pin
Dave Kreskowiak16-Jul-23 11:44
mveDave Kreskowiak16-Jul-23 11:44 
GeneralRe: Parameterized Query Pin
Richard Andrew x6416-Jul-23 12:39
professionalRichard Andrew x6416-Jul-23 12:39 
AnswerRe: Parameterized Query Pin
OriginalGriff16-Jul-23 12:24
mvaOriginalGriff16-Jul-23 12:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.