Nel

Nel

  • NA
  • 713
  • 953.5k

Connecting the combobox with a datatable

Aug 21 2011 12:30 PM
Hi,
I use ado.net commands not dataset to insert and modify data in my windows form. I have also a combobox which should contain values from another table (the primary key is in that table, but also the first table to which all other textboxes are connected contains one value as a foreign key from that table).
Could somebody help me how to connect the combobox as to be able to insert data in the first table (dokuments, which has currency field as a foreign field), choosing the value from the combobox which contains the data from the other table (Currency with currency field as a primary key)? 
Thanks in advance.

Now I have this in my code for insertion:
bool result = false;
  SqlConnection connection = null;
  try
  {
  connection = GetConnection();
  connection.Open();
  SqlCommand command = new SqlCommand("vnesiDok", connection);
  command.CommandType = CommandType.StoredProcedure;
 
  command.Parameters.AddWithValue("@vp", dokument.vp);
  //Here I should insert the value "valutaid" from the combobox as well

  command.Parameters.AddWithValue("@valutakurs", dokument.valutakurs);
  command.Parameters.AddWithValue("@imeprezime", dokument.imeprezime);
  command.Parameters.AddWithValue("@iznos", dokument.iznos);
  command.Parameters.AddWithValue("@iznosden", dokument.iznosden);
  command.Parameters.AddWithValue("@br_kas_izvod", dokument.br_kas_izvod);
  command.Parameters.AddWithValue("@br_patna_ska", dokument.br_patna_ska);
  command.Parameters.AddWithValue("@tip", dokument.tip);
  command.Parameters.AddWithValue("@data", dokument.datum);
  SqlParameter brdokParam = new SqlParameter(
  "@brdok", SqlDbType.Int);
  brdokParam.Direction = ParameterDirection.Output;
  command.Parameters.Add(brdokParam);
  int rowsAffected = command.ExecuteNonQuery();
  if (rowsAffected == 1)
  {
 
  dokument.brdok = (int)command.Parameters["@brdok"].Value;
  result = true;
  }
  }
Or I must use dataset?

Answers (4)