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. passing data

passing data

Scheduled Pinned Locked Moved C#
csharpdatabasehelpquestion
4 Posts 4 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.
  • B Offline
    B Offline
    Bong M
    wrote on last edited by
    #1

    I am a newbie, and I am starting to use the C# language, and I need a little help. Here goes: Main Form: I put a textbox where card number should be inputted. When the user presses the Enter key it should look into the database (table) the value of the textbox. Condition is: If only one (1) item found, the information will be displayed on the Main Form other textboxes. Otherwise if two or more items found, it will pass the card number to Form 2. Form 2: will be shown if Main Form calls Receive the card number passed by Main Form and search again the database (table) and display the items found on the datagridview. Then the user should select one (1) item, and pass back the single item with the complete (full) card number selected on the Main Form. My questions: How will I get the value of the current cell that I selected? How will I pass back the value I selected to the Main Form? How will Main Form receive the data being passed by Form 2? Many thanks! Form 1: public partial class MRRMainForm : Form { // start partial class MRRMainForm public String myConString = @"Provider=VFPOLEDB.1;" + @"Data Source=" + D:\\MyMaintable.DBF"; public String cardNumber; OleDbConnection con; OleDbDataAdapter da; OleDbCommand cmd = new OleDbCommand(); DataSet ds = new DataSet(); String commandSearch; public MRRMainForm() { InitializeComponent(); } private void txtCardNumber_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { // will trap other keys later.. //case Keys. // break; case Keys.Enter: findCardNumber(); txtDescription.Focus(); break; } // end switch } private void findCardNumber() { commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + txtCardNumber.Text + "\""; con = new OleDbConnection(myConString); cmd.CommandText = commandSearch; cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); da = new OleDbDataAdapter(cmd); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows.Count > 1) {

    J W J 3 Replies Last reply
    0
    • B Bong M

      I am a newbie, and I am starting to use the C# language, and I need a little help. Here goes: Main Form: I put a textbox where card number should be inputted. When the user presses the Enter key it should look into the database (table) the value of the textbox. Condition is: If only one (1) item found, the information will be displayed on the Main Form other textboxes. Otherwise if two or more items found, it will pass the card number to Form 2. Form 2: will be shown if Main Form calls Receive the card number passed by Main Form and search again the database (table) and display the items found on the datagridview. Then the user should select one (1) item, and pass back the single item with the complete (full) card number selected on the Main Form. My questions: How will I get the value of the current cell that I selected? How will I pass back the value I selected to the Main Form? How will Main Form receive the data being passed by Form 2? Many thanks! Form 1: public partial class MRRMainForm : Form { // start partial class MRRMainForm public String myConString = @"Provider=VFPOLEDB.1;" + @"Data Source=" + D:\\MyMaintable.DBF"; public String cardNumber; OleDbConnection con; OleDbDataAdapter da; OleDbCommand cmd = new OleDbCommand(); DataSet ds = new DataSet(); String commandSearch; public MRRMainForm() { InitializeComponent(); } private void txtCardNumber_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { // will trap other keys later.. //case Keys. // break; case Keys.Enter: findCardNumber(); txtDescription.Focus(); break; } // end switch } private void findCardNumber() { commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + txtCardNumber.Text + "\""; con = new OleDbConnection(myConString); cmd.CommandText = commandSearch; cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); da = new OleDbDataAdapter(cmd); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows.Count > 1) {

      J Offline
      J Offline
      JacquesDP
      wrote on last edited by
      #2

      Maybe look at a public method on form2 as your entry point from form1, in that public method you use as the entry point use a ref variable that will enable you to use the variable in form2 and what ever you changed it to in form2 it will return that value back to form1.

      He who laughs last is a bit on the slow side

      1 Reply Last reply
      0
      • B Bong M

        I am a newbie, and I am starting to use the C# language, and I need a little help. Here goes: Main Form: I put a textbox where card number should be inputted. When the user presses the Enter key it should look into the database (table) the value of the textbox. Condition is: If only one (1) item found, the information will be displayed on the Main Form other textboxes. Otherwise if two or more items found, it will pass the card number to Form 2. Form 2: will be shown if Main Form calls Receive the card number passed by Main Form and search again the database (table) and display the items found on the datagridview. Then the user should select one (1) item, and pass back the single item with the complete (full) card number selected on the Main Form. My questions: How will I get the value of the current cell that I selected? How will I pass back the value I selected to the Main Form? How will Main Form receive the data being passed by Form 2? Many thanks! Form 1: public partial class MRRMainForm : Form { // start partial class MRRMainForm public String myConString = @"Provider=VFPOLEDB.1;" + @"Data Source=" + D:\\MyMaintable.DBF"; public String cardNumber; OleDbConnection con; OleDbDataAdapter da; OleDbCommand cmd = new OleDbCommand(); DataSet ds = new DataSet(); String commandSearch; public MRRMainForm() { InitializeComponent(); } private void txtCardNumber_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { // will trap other keys later.. //case Keys. // break; case Keys.Enter: findCardNumber(); txtDescription.Focus(); break; } // end switch } private void findCardNumber() { commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + txtCardNumber.Text + "\""; con = new OleDbConnection(myConString); cmd.CommandText = commandSearch; cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); da = new OleDbDataAdapter(cmd); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows.Count > 1) {

        W Offline
        W Offline
        wasife
        wrote on last edited by
        #3

        1. For the first task, you can capture any suitable event of the DataGridView in which you can get the content of the selected cell like CellClick etc 2. To pass back the data to MainForm There are many ways to do it. I choose the simplest one. Create public properties in Second form and while closing this form, set the values of those properties with the selected values. 3. To get the data passed from form2 When the form2 closes, read the public properties created in step2

        1 Reply Last reply
        0
        • B Bong M

          I am a newbie, and I am starting to use the C# language, and I need a little help. Here goes: Main Form: I put a textbox where card number should be inputted. When the user presses the Enter key it should look into the database (table) the value of the textbox. Condition is: If only one (1) item found, the information will be displayed on the Main Form other textboxes. Otherwise if two or more items found, it will pass the card number to Form 2. Form 2: will be shown if Main Form calls Receive the card number passed by Main Form and search again the database (table) and display the items found on the datagridview. Then the user should select one (1) item, and pass back the single item with the complete (full) card number selected on the Main Form. My questions: How will I get the value of the current cell that I selected? How will I pass back the value I selected to the Main Form? How will Main Form receive the data being passed by Form 2? Many thanks! Form 1: public partial class MRRMainForm : Form { // start partial class MRRMainForm public String myConString = @"Provider=VFPOLEDB.1;" + @"Data Source=" + D:\\MyMaintable.DBF"; public String cardNumber; OleDbConnection con; OleDbDataAdapter da; OleDbCommand cmd = new OleDbCommand(); DataSet ds = new DataSet(); String commandSearch; public MRRMainForm() { InitializeComponent(); } private void txtCardNumber_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { // will trap other keys later.. //case Keys. // break; case Keys.Enter: findCardNumber(); txtDescription.Focus(); break; } // end switch } private void findCardNumber() { commandSearch = "Select * from MyMaintable where substr(prod_code,6,7)=\"" + txtCardNumber.Text + "\""; con = new OleDbConnection(myConString); cmd.CommandText = commandSearch; cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); da = new OleDbDataAdapter(cmd); da.Fill(ds); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows.Count > 1) {

          J Offline
          J Offline
          JeffPClark
          wrote on last edited by
          #4

          Just have the MultiplesFound form expose a public property indicating the row that was selected by the user. if (ds.Tables[0].Rows.Count > 0) { //Used if there is only one Row returned. int SelectedRow = 0; if (ds.Tables[0].Rows.Count > 1) { cardNumber = txtCardNumber.Text; MultiplesFound myMF = new MultiplesFound(cardNumber); myMF.myCardNumber = cardNumber; myMF.ShowDialog(); //Retrieve the row selection SelectedRow = myMF.SelectedRow; } //Display the selected Row (or first row when only one has been returned txtProductCode.DataBindings.Add("text", ds.Tables[SelectedRow], "prod_code"); txtDescription.DataBindings.Add("text", ds.Tables[SelectedRow], "prod_desc"); txtModelNumber.DataBindings.Add("text", ds.Tables[SelectedRow], "model_no"); }

          Jeff Clark Systems Architect JP Clark, INC. Columbus, Ohio

          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