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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Linking a text box to a unique ID in C# windows app.

Linking a text box to a unique ID in C# windows app.

Scheduled Pinned Locked Moved C#
csharp
7 Posts 2 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.
  • N Offline
    N Offline
    ndeza
    wrote on last edited by
    #1

    Hi All, I'm still new to development, I'm trying to link a text box to an ID in a table. This text box will be an identfier and it will insert the text to the table when it has linked to the id. Is this possible or should i look into something else. Regards, Ndeza

    S 1 Reply Last reply
    0
    • N ndeza

      Hi All, I'm still new to development, I'm trying to link a text box to an ID in a table. This text box will be an identfier and it will insert the text to the table when it has linked to the id. Is this possible or should i look into something else. Regards, Ndeza

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi Ndeza, sure, this is possible (You could write a whole rocket steering application in C# if you like, am I right?) . But please be sure to post more information about the issue. What kind of table, what kind of Id? What do you want to achieve exactly. Regards Sebastian

      N 1 Reply Last reply
      0
      • S SeMartens

        Hi Ndeza, sure, this is possible (You could write a whole rocket steering application in C# if you like, am I right?) . But please be sure to post more information about the issue. What kind of table, what kind of Id? What do you want to achieve exactly. Regards Sebastian

        N Offline
        N Offline
        ndeza
        wrote on last edited by
        #3

        Hi Sebastian, I've got a Foreign Exchange app that I'm trying to create, and the table is stored in the database. This table has an ID where it links to the different currencies. Now what I want to do is I want to link the text boxes of all the different currencies to the currencies in the table. I haven't done much with this but I've created a stored proc that updates, and inserts. cmd.Parameters.Add("@PlayerTypeID", SqlDbType.Int, 20); cmd.Parameters["@PlayerTypeID"].Value = txt0.Text; -- this is what I’ve been trying and it’s not working out. cmd.Parameters.Add("@DateYear", SqlDbType.Int, 40); cmd.Parameters["@DateYear"].Value = cbmYear.SelectedItem; cmd.Parameters.Add("@DateMonth", SqlDbType.Int, 4); cmd.Parameters["@DateMonth"].Value = cmbMonth.SelectedItem; cmd.Parameters.Add("@FXR", SqlDbType.Float); cmd.Parameters["@FXR"].Value = txt0.Text; cmd.Parameters["@FXR"].Value = txt3.Text; cmd.Parameters["@FXR"].Value = txt5.Text; cmd.Parameters["@FXR"].Value = txt6.Text; cmd.Parameters["@FXR"].Value = txt9.Text; cmd.Parameters["@FXR"].Value = txt55.Text; cmd.Parameters["@FXR"].Value = txt61.Text; cmd.Parameters["@FXR"].Value = txt76.Text; cmd.Parameters["@FXR"].Value = txt77.Text; cmd.Parameters["@FXR"].Value = txt81.Text; But now my problem is that I just cant get the PlayerTypeID being the ID link to the text box. Please can you assist with an example of some kind. Thank you, Ndeza

        S 1 Reply Last reply
        0
        • N ndeza

          Hi Sebastian, I've got a Foreign Exchange app that I'm trying to create, and the table is stored in the database. This table has an ID where it links to the different currencies. Now what I want to do is I want to link the text boxes of all the different currencies to the currencies in the table. I haven't done much with this but I've created a stored proc that updates, and inserts. cmd.Parameters.Add("@PlayerTypeID", SqlDbType.Int, 20); cmd.Parameters["@PlayerTypeID"].Value = txt0.Text; -- this is what I’ve been trying and it’s not working out. cmd.Parameters.Add("@DateYear", SqlDbType.Int, 40); cmd.Parameters["@DateYear"].Value = cbmYear.SelectedItem; cmd.Parameters.Add("@DateMonth", SqlDbType.Int, 4); cmd.Parameters["@DateMonth"].Value = cmbMonth.SelectedItem; cmd.Parameters.Add("@FXR", SqlDbType.Float); cmd.Parameters["@FXR"].Value = txt0.Text; cmd.Parameters["@FXR"].Value = txt3.Text; cmd.Parameters["@FXR"].Value = txt5.Text; cmd.Parameters["@FXR"].Value = txt6.Text; cmd.Parameters["@FXR"].Value = txt9.Text; cmd.Parameters["@FXR"].Value = txt55.Text; cmd.Parameters["@FXR"].Value = txt61.Text; cmd.Parameters["@FXR"].Value = txt76.Text; cmd.Parameters["@FXR"].Value = txt77.Text; cmd.Parameters["@FXR"].Value = txt81.Text; But now my problem is that I just cant get the PlayerTypeID being the ID link to the text box. Please can you assist with an example of some kind. Thank you, Ndeza

          S Offline
          S Offline
          SeMartens
          wrote on last edited by
          #4

          Hmm... still not sure if I understand everything. All you do here is to put the text of the txt0-Textbox into the PlayerTypeID (same for the @FXR values). So you write all the values stored in your textboxes into the database... If you change sth. within the database it will not automatically change in your app... Could you please explain in more detail what you mean by "link the textboxes ... in the table". What means "link"? Regards, Sebastian

          N 1 Reply Last reply
          0
          • S SeMartens

            Hmm... still not sure if I understand everything. All you do here is to put the text of the txt0-Textbox into the PlayerTypeID (same for the @FXR values). So you write all the values stored in your textboxes into the database... If you change sth. within the database it will not automatically change in your app... Could you please explain in more detail what you mean by "link the textboxes ... in the table". What means "link"? Regards, Sebastian

            N Offline
            N Offline
            ndeza
            wrote on last edited by
            #5

            Ok, For each currency there is an ID, what I'm trying to do is make the Text box that I will also enter the new exchange rate into, the text box will correspond with the ID(PlayerTypeID). Basically, I’m trying to make the text box be an Id identifier and also an input text that will update the @FXR. What I mean by link; I want the text box to identify the id in which it will enter the new exchange rate. Thank you, Ndeza

            S 1 Reply Last reply
            0
            • N ndeza

              Ok, For each currency there is an ID, what I'm trying to do is make the Text box that I will also enter the new exchange rate into, the text box will correspond with the ID(PlayerTypeID). Basically, I’m trying to make the text box be an Id identifier and also an input text that will update the @FXR. What I mean by link; I want the text box to identify the id in which it will enter the new exchange rate. Thank you, Ndeza

              S Offline
              S Offline
              SeMartens
              wrote on last edited by
              #6

              Alright, now i'm getting close to the point. I thin k you have two options here: ------------- First one: Use a dictionary to store the textbox and the playerid. Looks somethind like this:

              // create the dictionary
              Dictionary<textbox,> dictBoxes = new Dictionary<textbox,>();
              // than put the id in it
              dictBoxes.Add(txt0, /* the player id goes here */ );

              In your storing method you can then access the value:

              cmd.Parameters["@PlayerTypeID"].Value = dictBoxes[txt0];

              --------------- Second option is to inherit the textbox and add another property:

              public class MyPlayerIDTextbox:Textbox {

              private string m_sPlayerID;

              public string PlayerID {
              get { return this.m_sPlayerID;}
              set { this.m_sPlayerID = value;}
              }
              }

              Than you have to set the playerid of your textbox once:

              MyPlayerIDTextbox txt0 = new MyPlayerIDTextbox();
              txt0.PlayerID = /* the player id goes here */

              And the storing method will look like this:

              cmd.Parameters["@PlayerTypeID"].Value = txt0.PlayerID;

              Hope this helps you a bit. Regards Sebastian P.S: I would prefer the dictionary method, it is simplier I think. Or any other suggestions?

              N 1 Reply Last reply
              0
              • S SeMartens

                Alright, now i'm getting close to the point. I thin k you have two options here: ------------- First one: Use a dictionary to store the textbox and the playerid. Looks somethind like this:

                // create the dictionary
                Dictionary<textbox,> dictBoxes = new Dictionary<textbox,>();
                // than put the id in it
                dictBoxes.Add(txt0, /* the player id goes here */ );

                In your storing method you can then access the value:

                cmd.Parameters["@PlayerTypeID"].Value = dictBoxes[txt0];

                --------------- Second option is to inherit the textbox and add another property:

                public class MyPlayerIDTextbox:Textbox {

                private string m_sPlayerID;

                public string PlayerID {
                get { return this.m_sPlayerID;}
                set { this.m_sPlayerID = value;}
                }
                }

                Than you have to set the playerid of your textbox once:

                MyPlayerIDTextbox txt0 = new MyPlayerIDTextbox();
                txt0.PlayerID = /* the player id goes here */

                And the storing method will look like this:

                cmd.Parameters["@PlayerTypeID"].Value = txt0.PlayerID;

                Hope this helps you a bit. Regards Sebastian P.S: I would prefer the dictionary method, it is simplier I think. Or any other suggestions?

                N Offline
                N Offline
                ndeza
                wrote on last edited by
                #7

                Heya Sebastian, Wow you were right the Dictionary works perfect, but the only thing is that I have allot of exchange rates to update and insert and it only inserts for one where as I'm trying to insert in one go. Please can you assist if you can? Oh the second option is quite complicated as you will need to convert a string to an INT32. But I prefer the First Option much easier and more understandable. Regards, Ndeza /// create the dictionary Dictionary<TextBox, int> dictBoxes = new Dictionary<TextBox, int>(); /// than put the id in it dictBoxes.Add(txt0, 0); dictBoxes.Add(txt3, 3); dictBoxes.Add(txt5, 5); dictBoxes.Add(txt55, 55); dictBoxes.Add(txt6, 6); dictBoxes.Add(txt61, 61); dictBoxes.Add(txt76, 76); dictBoxes.Add(txt77, 77); dictBoxes.Add(txt81, 81); dictBoxes.Add(txt9, 9); //All the parameters that will be added to the database //also all the from the app cmd.Parameters.Add("@PlayerTypeID", SqlDbType.Int, 20); cmd.Parameters.Add("@DateYear", SqlDbType.Int, 40); cmd.Parameters.Add("@DateMonth", SqlDbType.Int, 4); cmd.Parameters.Add("@FXR", SqlDbType.Float); //Assigning the Values to the parameters cmd.Parameters["@PlayerTypeID"].Value = txt0.Text; cmd.Parameters["@PlayerTypeID"].Value = txt3.Text; cmd.Parameters["@PlayerTypeID"].Value = txt5.Text; cmd.Parameters["@DateYear"].Value = cbmYear.SelectedItem; cmd.Parameters["@DateMonth"].Value = cmbMonth.SelectedItem; cmd.Parameters["@FXR"].Value = txt0.Text; cmd.Parameters["@FXR"].Value = txt3.Text; cmd.Parameters["@FXR"].Value = txt5.Text; cmd.Parameters["@FXR"].Value = txt6.Text; cmd.Parameters["@FXR"].Value = txt9.Text; cmd.Parameters["@FXR"].Value = txt55.Text; cmd.Parameters["@FXR"].Value = txt61.Text; cmd.Parameters["@FXR"].Value = txt76.Text; cmd.Parameters["@FXR"].Value = txt77.Text; cmd.Parameters["@FXR"].Value = txt81.Text;

                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