carlito

carlito

  • NA
  • 6
  • 2.9k

Insert statment to actuall code

Sep 29 2011 3:37 PM
Hello,
 
This is my three tables in database:

tb_plane
============
plane_id plane_name tb_attributes
==============
attribute_id
attribute_name

tb_as_plane_attributes
========================
plane_attribute_id
FK_plane_id
FK_attribute_id value 

On my Form I got 1 combobox which is populated by plane_name's from tb_plane and datagridview (GrdAttributes) which is populate by all attribute_name's from tb_attributes and one extra column named "Value" where the user can put some decimal/integer values. What I need is to make Insert Button Click event to put attributes with values which wrote user to plane selected in combobox and there where in GrdAttributes did not wrote value in column Value by user did not send to tb_as_plane_attributes
 
I did a code to populate combbox and i prepare datagridview. Perhaps I need to check GrdAllAttributes.Rows to see values is contains after the user has entered data but I don;t know how to do that. If anyone could help will be good. That's my code

private SqlDataAdapter CreateDataAdapter(string sql) { return new SqlDataAdapter(sql, conSettings.ConnectionString); }   private DataSet GetDataSet(string tableName, string sql) { DataSet dataSet = new DataSet(); CreateDataAdapter(selectCommandText).Fill(dataSet, tableName); return dataSet; }   private DataTable GetDataTable(string sql) { DataTable dt = new DataTable(); CreateDataAdapter(selectCommandText).Fill(dt); return dt; }   private void PopulatePlainComboBox() { try { CboPlains.DataSource = GetDataTable("SELECT plane_id, plane_name FROM tb_plane"); CboPlains.DisplayMember = "plane_name"; CboPlains.ValueMember = "plane_id"; } catch (System.Exception ex) { string str = "Source:" + ex.Source + "\n" + "Message:" + ex.Message; MessageBox.Show(str, "Generic Exception"); } }   private void PopulateGridByAttributes()         {             DataTable dataTable = GetDataTable("SELECT attribute_id, attribute_name FROM tb_attributes");             GrdAllAttributes.Columns.Add("attribute_name", "name of attribute");             GrdAllAttributes.Columns.Add("dd", "Value");               foreach (DataRow row in dataTable.Rows)             {                 GrdAllAttributes.Rows.Add(row[1]);             }         }


Answers (1)