Click here to Skip to main content
15,896,444 members
Home / Discussions / C#
   

C#

 
AnswerRe: New Kind of Application for me (centralized/cloud). Looking for learning resources. Pin
Gerry Schmitz30-Jul-23 4:05
mveGerry Schmitz30-Jul-23 4:05 
Questionweb controls in windows forms Pin
mjcs10027-Jul-23 6:14
mjcs10027-Jul-23 6:14 
AnswerRe: web controls in windows forms Pin
Richard MacCutchan27-Jul-23 6:39
mveRichard MacCutchan27-Jul-23 6:39 
AnswerRe: web controls in windows forms Pin
Dave Kreskowiak27-Jul-23 8:00
mveDave Kreskowiak27-Jul-23 8:00 
AnswerRe: web controls in windows forms Pin
Pete O'Hanlon27-Jul-23 22:04
mvePete O'Hanlon27-Jul-23 22:04 
GeneralRe: web controls in windows forms Pin
Dave Kreskowiak28-Jul-23 8:45
mveDave Kreskowiak28-Jul-23 8:45 
AnswerRe: web controls in windows forms Pin
Gerry Schmitz28-Jul-23 5:19
mveGerry Schmitz28-Jul-23 5:19 
AnswerRe: web controls in windows forms Pin
pr1mem0ver29-Jul-23 21:13
pr1mem0ver29-Jul-23 21:13 
GeneralRe: web controls in windows forms Pin
OriginalGriff29-Jul-23 21:22
mveOriginalGriff29-Jul-23 21:22 
GeneralRe: web controls in windows forms Pin
pr1mem0ver30-Jul-23 10:32
pr1mem0ver30-Jul-23 10:32 
GeneralRe: web controls in windows forms Pin
OriginalGriff30-Jul-23 18:29
mveOriginalGriff30-Jul-23 18:29 
AnswerRe: web controls in windows forms Pin
Graeme_Grant19-Aug-23 15:10
mvaGraeme_Grant19-Aug-23 15:10 
QuestionKindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 20:18
Hillymalen26-Jul-23 20:18 
AnswerRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 20:26
mveOriginalGriff26-Jul-23 20:26 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 20:55
Hillymalen26-Jul-23 20:55 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 21:40
mveOriginalGriff26-Jul-23 21:40 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 22:00
Hillymalen26-Jul-23 22:00 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 22:08
mveOriginalGriff26-Jul-23 22:08 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 22:13
Hillymalen26-Jul-23 22:13 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Ralf Meier26-Jul-23 22:35
mveRalf Meier26-Jul-23 22:35 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 22:47
mveOriginalGriff26-Jul-23 22:47 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 22:45
mveOriginalGriff26-Jul-23 22:45 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
Hillymalen26-Jul-23 23:23
Hillymalen26-Jul-23 23: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
OriginalGriff26-Jul-23 23:40
mveOriginalGriff26-Jul-23 23:40 
GeneralRe: Kindly help me i tried to do it for 3 days but i could not solve it. Pin
OriginalGriff26-Jul-23 23:47
mveOriginalGriff26-Jul-23 23:47 

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.