title: Converting datatable to int directly in c#
body: <p>I tried to convert a datatable that just has one field (the field's data is primary key) to int , in order to using in sql commands such as Select and etc.
  but it fails!
  and when i cast it to an object or convert it to string first , the commands gone wrong!
  please help me</p>
  
  <hr>
  
  <p>i want to select * from a table which has a foreign key where the foreign code equals by an int value that has been selected from a table in another sql command and returned as a datatable row with just one field.</p>
  
  <p>here is my code :</p>
  
  <p><strong>class mydata</strong> :</p>
  
  <pre><code>public string strsql;
          public DataTable showData()
          {
              SqlConnection Con1 = new SqlConnection("Data Source=.;database=daneshgah;integrated security=true");
              Con1.Open();
              SqlDataAdapter da = new SqlDataAdapter(strsql, Con1);
              DataTable dt = new DataTable();
              da.Fill(dt);
              Con1.Close();
              return (dt);
  
          }
  </code></pre>
  
  <p><strong>button event :</strong> </p>
  
  <pre><code>    myData search = new myData();
                  int aa = int.Parse(txt_stdcourse.Text);
                  search.strsql = "select tchNo from University where couNo='" + aa + "'";
                  DataTable a = search.showData();
                   string b = a.Rows[0][0].ToString();
                      int c = int.Parse(b);
                      myData akhz = new myData();
                      akhz.strsql = "insert into stc (couNo,tchNo,stuNo)values('" + aa + "','" + c + "','" + id + "')";
                      akhz.Data();
                      lbl_stdcourseok.Visible = false;
                      lbl_stdcourseok.Visible = true;
  </code></pre>