Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. displaying data from 1 form to another

displaying data from 1 form to another

Scheduled Pinned Locked Moved C#
csharpdatabase
15 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C csanda1

    Id like source code to do that csanda

    A Offline
    A Offline
    Andrei Ungureanu
    wrote on last edited by
    #4

    csanda1 wrote:

    Id like source code to do that

    Well this is not nice to say around here. Tell us what you tried, and what it's not working and then you'll get some help.

    I will use Google before asking dumb questions

    1 Reply Last reply
    0
    • C csanda1

      Id like source code to do that csanda

      A Offline
      A Offline
      Andrei Ungureanu
      wrote on last edited by
      #5

      Your problem might be the databinding...see where it's done...Maybe we could help you better if you would post some of your code.

      I will use Google before asking dumb questions

      C 1 Reply Last reply
      0
      • C csanda1

        Id like source code to do that csanda

        J Offline
        J Offline
        Joe 2
        wrote on last edited by
        #6

        Tell me how much you can owe me?. I will take up that task.

        Once you have mastered the ability to turn yourself invisible at will, and to deflect bullets with your hair, you will be ready to come back here to the lounge and post programming questions.Only at this point will you be able to dodge the fireballs that are going to come your way. - Pete O'Hanlon

        C 1 Reply Last reply
        0
        • A Andrei Ungureanu

          Your problem might be the databinding...see where it's done...Maybe we could help you better if you would post some of your code.

          I will use Google before asking dumb questions

          C Offline
          C Offline
          csanda1
          wrote on last edited by
          #7

          Sorry for being vague.This is the code in form 2 private void button1_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string Company = txtSearch.Text; string select = "SELECT * FROM ecmain WHERE CompanyName Like '" + Company + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(select, datatryConn); DataSet ds = new DataSet(); da.Fill(ds, "ecmain"); update frm = new update(txtSearch.Text ); frm.Show(); datatryConn.Close(); code in form 2 private void btnUpdate_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string select = "Update ecmain SET CompanyName ='" + txtCompany.Text + "' , ContactName ='" + txtName.Text + "',ContactSurname='" + txtSurname.Text + "', Designation='" + txtDesignation.Text + "',TelephoneNumber='" + txtTel.Text + "', Faxnumber= '" + txtFax.Text + "', Email='" + txtEmail.Text + "',City/Town='" + txtCity.Text + "',PostCode='" + txtPost.Text + "',NumberofEmployees='" + txtEmployees.Text + "', Export='" + cbxExport.SelectedItem + "',ExportDestinations='" + txtDestination.Text + "', SIC Product 1='" + txtSic1.Text + "', Product1_Description='" + txtProduct1.Text + "', SICProduct2='" + txtSic2.Text + "', Product2Description='" + txtProduct2.Text + "', SICProduct3='" + txtSic3.Text + "', Product3Description='" + txtProduct3.Text + "', GeneralComments='" + txtComment.Text + "', Complete='" + cbxComplete.SelectedItem + "' Where CompanyName='" + txtSearch.Text + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); OleDbCommand cmd = new OleDbCommand(select, datatryConn); datatryConn.Open(); cmd.ExecuteNonQuery(); datatryConn.Close(); MessageBox.Show("Updated successfully!"); } Easy guys im new to programming csanda

          A 1 Reply Last reply
          0
          • J Joe 2

            Tell me how much you can owe me?. I will take up that task.

            Once you have mastered the ability to turn yourself invisible at will, and to deflect bullets with your hair, you will be ready to come back here to the lounge and post programming questions.Only at this point will you be able to dodge the fireballs that are going to come your way. - Pete O'Hanlon

            C Offline
            C Offline
            csanda1
            wrote on last edited by
            #8

            Ill owe u big time. Pliz help

            B 1 Reply Last reply
            0
            • C csanda1

              Sorry for being vague.This is the code in form 2 private void button1_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string Company = txtSearch.Text; string select = "SELECT * FROM ecmain WHERE CompanyName Like '" + Company + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(select, datatryConn); DataSet ds = new DataSet(); da.Fill(ds, "ecmain"); update frm = new update(txtSearch.Text ); frm.Show(); datatryConn.Close(); code in form 2 private void btnUpdate_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string select = "Update ecmain SET CompanyName ='" + txtCompany.Text + "' , ContactName ='" + txtName.Text + "',ContactSurname='" + txtSurname.Text + "', Designation='" + txtDesignation.Text + "',TelephoneNumber='" + txtTel.Text + "', Faxnumber= '" + txtFax.Text + "', Email='" + txtEmail.Text + "',City/Town='" + txtCity.Text + "',PostCode='" + txtPost.Text + "',NumberofEmployees='" + txtEmployees.Text + "', Export='" + cbxExport.SelectedItem + "',ExportDestinations='" + txtDestination.Text + "', SIC Product 1='" + txtSic1.Text + "', Product1_Description='" + txtProduct1.Text + "', SICProduct2='" + txtSic2.Text + "', Product2Description='" + txtProduct2.Text + "', SICProduct3='" + txtSic3.Text + "', Product3Description='" + txtProduct3.Text + "', GeneralComments='" + txtComment.Text + "', Complete='" + cbxComplete.SelectedItem + "' Where CompanyName='" + txtSearch.Text + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); OleDbCommand cmd = new OleDbCommand(select, datatryConn); datatryConn.Open(); cmd.ExecuteNonQuery(); datatryConn.Close(); MessageBox.Show("Updated successfully!"); } Easy guys im new to programming csanda

              A Offline
              A Offline
              Andrei Ungureanu
              wrote on last edited by
              #9

              where is button1 and btnUpdate? You wrote that the whole code is placed in the second form...you got me confused.

              I will use Google before asking dumb questions

              C 1 Reply Last reply
              0
              • C csanda1

                Id like source code to do that csanda

                B Offline
                B Offline
                benjymous
                wrote on last edited by
                #10

                If your forms are modeless, then in form2, add a string property, in form1, after the user has changed text in the text box, change that property on form2. if your form2 is modal, then add the string from the text box as a parameter to the constructor of form2.

                -- Help me! I'm turning into a grapefruit! Buzzwords!

                1 Reply Last reply
                0
                • C csanda1

                  Ill owe u big time. Pliz help

                  B Offline
                  B Offline
                  benjymous
                  wrote on last edited by
                  #11

                  I have just helped - what I described are fairly fundamental features of the C# language, so you if you don't understand that, I'd suggest you find yourself a good book on the subject

                  -- Help me! I'm turning into a grapefruit! Buzzwords!

                  1 Reply Last reply
                  0
                  • A Andrei Ungureanu

                    where is button1 and btnUpdate? You wrote that the whole code is placed in the second form...you got me confused.

                    I will use Google before asking dumb questions

                    C Offline
                    C Offline
                    csanda1
                    wrote on last edited by
                    #12

                    Ok its like this.Form1 has txtsearch and button1 for search.When u type the company name in the textbox and click the button it shows the update form. This code is in form1 private void button1_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string Company = txtSearch.Text; string select = "SELECT * FROM ecmain WHERE CompanyName Like '" + Company + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(select, datatryConn); DataSet ds = new DataSet(); da.Fill(ds, "ecmain"); update frm = new update(txtSearch.Text ); frm.Show(); datatryConn.Close(); Form2 is named update, it has a datagridview and textboxes, now what i need is when I click button1 in form1 the search results to appear in the datagridview in form2 This is the update code in form 2 private void btnUpdate_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string select = "Update ecmain SET CompanyName ='" + txtCompany.Text + "' , ContactName ='" + txtName.Text + "',ContactSurname='" + txtSurname.Text + "', Designation='" + txtDesignation.Text + "',TelephoneNumber='" + txtTel.Text + "', Faxnumber= '" + txtFax.Text + "', Email='" + txtEmail.Text + "',City/Town='" + txtCity.Text + "',PostCode='" + txtPost.Text + "',NumberofEmployees='" + txtEmployees.Text + "', Export='" + cbxExport.SelectedItem + "',ExportDestinations='" + txtDestination.Text + "', SIC Product 1='" + txtSic1.Text + "', Product1_Description='" + txtProduct1.Text + "', SICProduct2='" + txtSic2.Text + "', Product2Description='" + txtProduct2.Text + "', SICProduct3='" + txtSic3.Text + "', Product3Description='" + txtProduct3.Text + "', GeneralComments='" + txtComment.Text + "', Complete='" + cbxComplete.SelectedItem + "' Where CompanyName='" + txtSearch.Text + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); OleDbCommand cmd = new OleDbCommand(select, datatryConn); datatryConn.Open(); cmd.ExecuteNonQuery(); datatryConn.Close(); MessageBox.Show("Updated successfully!"); } csanda

                    A P 2 Replies Last reply
                    0
                    • C csanda1

                      Hi I have 2 forms in my C# windows application. I type a value in a textbox in form1 and want to populate the results in a datagridview in form2 but its not getting populated. In form2 i have a datagridview and text boxes whose values are binded from db. Thanx csanda

                      A Offline
                      A Offline
                      Aparna B
                      wrote on last edited by
                      #13

                      select the datagrid and right click it a pop up menu will displayed inside that u will find Choose Data Source inside that u give the database name and the table name it will automatically displays the datas that are binded inside the table on the page load itself....

                      1 Reply Last reply
                      0
                      • C csanda1

                        Ok its like this.Form1 has txtsearch and button1 for search.When u type the company name in the textbox and click the button it shows the update form. This code is in form1 private void button1_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string Company = txtSearch.Text; string select = "SELECT * FROM ecmain WHERE CompanyName Like '" + Company + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(select, datatryConn); DataSet ds = new DataSet(); da.Fill(ds, "ecmain"); update frm = new update(txtSearch.Text ); frm.Show(); datatryConn.Close(); Form2 is named update, it has a datagridview and textboxes, now what i need is when I click button1 in form1 the search results to appear in the datagridview in form2 This is the update code in form 2 private void btnUpdate_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string select = "Update ecmain SET CompanyName ='" + txtCompany.Text + "' , ContactName ='" + txtName.Text + "',ContactSurname='" + txtSurname.Text + "', Designation='" + txtDesignation.Text + "',TelephoneNumber='" + txtTel.Text + "', Faxnumber= '" + txtFax.Text + "', Email='" + txtEmail.Text + "',City/Town='" + txtCity.Text + "',PostCode='" + txtPost.Text + "',NumberofEmployees='" + txtEmployees.Text + "', Export='" + cbxExport.SelectedItem + "',ExportDestinations='" + txtDestination.Text + "', SIC Product 1='" + txtSic1.Text + "', Product1_Description='" + txtProduct1.Text + "', SICProduct2='" + txtSic2.Text + "', Product2Description='" + txtProduct2.Text + "', SICProduct3='" + txtSic3.Text + "', Product3Description='" + txtProduct3.Text + "', GeneralComments='" + txtComment.Text + "', Complete='" + cbxComplete.SelectedItem + "' Where CompanyName='" + txtSearch.Text + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); OleDbCommand cmd = new OleDbCommand(select, datatryConn); datatryConn.Open(); cmd.ExecuteNonQuery(); datatryConn.Close(); MessageBox.Show("Updated successfully!"); } csanda

                        A Offline
                        A Offline
                        Andrei Ungureanu
                        wrote on last edited by
                        #14

                        You can create a public method in the second form, let's say BindData(). After you call the second's form constructor in button1_Click event, you call that method before showing the second form. Like this:

                        update frm = new update(txtSearch.Text );
                        frm.BindData();
                        frm.Show();

                        Make sure that the BindData method is the one that binds the gridview and the textboxes to the database according with the text the form received in it's constructor. Hope it helps.

                        I will use Google before asking dumb questions

                        1 Reply Last reply
                        0
                        • C csanda1

                          Ok its like this.Form1 has txtsearch and button1 for search.When u type the company name in the textbox and click the button it shows the update form. This code is in form1 private void button1_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string Company = txtSearch.Text; string select = "SELECT * FROM ecmain WHERE CompanyName Like '" + Company + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); datatryConn.Open(); OleDbDataAdapter da = new OleDbDataAdapter(select, datatryConn); DataSet ds = new DataSet(); da.Fill(ds, "ecmain"); update frm = new update(txtSearch.Text ); frm.Show(); datatryConn.Close(); Form2 is named update, it has a datagridview and textboxes, now what i need is when I click button1 in form1 the search results to appear in the datagridview in form2 This is the update code in form 2 private void btnUpdate_Click(object sender, EventArgs e) { string strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=datatry.mdb"; string select = "Update ecmain SET CompanyName ='" + txtCompany.Text + "' , ContactName ='" + txtName.Text + "',ContactSurname='" + txtSurname.Text + "', Designation='" + txtDesignation.Text + "',TelephoneNumber='" + txtTel.Text + "', Faxnumber= '" + txtFax.Text + "', Email='" + txtEmail.Text + "',City/Town='" + txtCity.Text + "',PostCode='" + txtPost.Text + "',NumberofEmployees='" + txtEmployees.Text + "', Export='" + cbxExport.SelectedItem + "',ExportDestinations='" + txtDestination.Text + "', SIC Product 1='" + txtSic1.Text + "', Product1_Description='" + txtProduct1.Text + "', SICProduct2='" + txtSic2.Text + "', Product2Description='" + txtProduct2.Text + "', SICProduct3='" + txtSic3.Text + "', Product3Description='" + txtProduct3.Text + "', GeneralComments='" + txtComment.Text + "', Complete='" + cbxComplete.SelectedItem + "' Where CompanyName='" + txtSearch.Text + "'"; OleDbConnection datatryConn = new OleDbConnection(strConnection); OleDbCommand cmd = new OleDbCommand(select, datatryConn); datatryConn.Open(); cmd.ExecuteNonQuery(); datatryConn.Close(); MessageBox.Show("Updated successfully!"); } csanda

                          P Offline
                          P Offline
                          Pete OHanlon
                          wrote on last edited by
                          #15

                          Please don't have direct queries like this. It's just bad practice. Instead, take a look at using Command Parameters - they are your friend, and they remove a lot of vulnerabilities from your application (take a look at this[^] article). Also take a look at this[^] article on passing values between forms.

                          Deja View - the feeling that you've seen this post before.

                          My blog | My articles

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups