title: c# Enter value into datatable via different forms
body: <p>I have a c# project with 4+ forms (parent-child relationship). In Form01 I create a datatable with initial 'Rating' values in it assigned to variable 'Horse':</p>
  
  <pre><code>public Form01()
          {
              InitializeComponent();
              dgvMeetings.DataSource = GetMeetings();
              dtRatings = GetRating();
          }
  </code></pre>
  
  <p>dtRatings table is produced by an SQL call as follows:</p>
  
  <pre><code>public DataTable GetRating()
          {
              DataTable dtRating = new DataTable();
              string connString = ConfigurationManager.ConnectionStrings["dbx"].ConnectionString;
              using (SqlConnection con = new SqlConnection(connString))
              {
                  using (SqlCommand cmd = new SqlCommand(@"SELECT 
                                                            Course
                                                          , Race
                                                          , Cloth
                                                          , Horse
                                                          , Rating
                                                          , Odds
                                                          FROM[Smartform].[dbo].[Entries]
                                                          where Date = convert(date, getdate() - 1) 
                                                          order by 1, 2, 3", con))
                  {
                      con.Open();
                      SqlDataReader reader = cmd.ExecuteReader();
                      dtRating.Load(reader);
                  }
              }
              return dtRating;
          }
  </code></pre>
  
  <p>In Form4, I want to be able to update the 'Rating' value in dtRating by entering a value into a text box. I have been attempting to do this via a textbox-keyup call as follows:</p>
  
  <pre><code>private void TbxForm01_KeyUp(object sender, KeyEventArgs e)
          {
              if (e.KeyData == Keys.Enter)
              {
                  string searchExpression = "Horse = " + Form03.Horse;
                  MessageBox.Show(searchExpression);
                  DataRow[] foundRows;
                  foundRows = Form01.dtRatings.Select(searchExpression);
                  MessageBox.Show(foundRows.ToString());
  
              }
          }
  </code></pre>
  
  <p>As you can see i have only just started. My plan was to use Form03.Horse to look up Horse on dtRatings and retrieve row number. Then use that to overwrite rating value with textbox value. </p>
  
  <p>The 1st messagebox shows the correct 'Horse' name. However, I can't get the foundrows expression to work and correctly retrieve the row number from dtRatings. </p>
  
  <p>Can anyone help with this and show me how to overwrite rating value in dtRatings with textbox entered value?</p>
  
  <p>Thanks.</p>