By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,914 Members | 563 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,914 IT Pros & Developers. It's quick & easy.

How to get the selected item in the Combobox and Textbox

P: 53
Hello,

I have a Datagridview which has a combobox,and 2 textbox, The combobox is bound to a Datasource(Database Sql Server and the table name is Category)
,and Datagridview is not bounded to any datasource. When the user selects an item in the combobox,and enters the item(text) in the 2 text box , I want all the 3(combobox selected item, and the entered text in the 2 textbox) of them to store it a a table name called Transact_tabletrialone.(columns for Transact_tabletrialone are categoryname, description,amount)

I am using a stored procedure and the code below

Expand|Select|Wrap|Line Numbers
  1.  
  2. void savetotransact_table()
  3.         {
  4.  
  5.           //SqlDataAdapter TransactDataAdapter = new SqlDataAdapter(new SqlCommand("SELECT description,amount FROM Transact_table", connection));
  6.           SqlDataAdapter TransactDataAdapter = new SqlDataAdapter(new SqlCommand("SELECT * FROM Transact_tabletrialone", connection));
  7.           cDS.Clear();
  8.           TransactDataAdapter.Fill(cDS, "Transact_tabletrialone");
  9.           DataRow cOrderRow = cDS.Tables["Transact_tabletrialone"].NewRow();//name of the table ,and rowobject
  10.           cOrderRow["categoryname"] = dataGridView1.Columns[0].Selected;
  11.           cOrderRow["description"] = dataGridView1.Columns[1].Selected;
  12.              //dataGridView1.Rows[dataGridView1.CurrentRow];//name of the column
  13.           cOrderRow["amount"] = dataGridView1.Columns[2].Selected;//dataGridView1.Columns[2].HeaderText;
  14.           // cOrderRow["categoryid"] = 
  15.           cDS.Tables["Transact_tabletrialone"].Rows.Add(cOrderRow);
  16.  
  17.          TransactDataAdapter.InsertCommand = new SqlCommand("databaseinserttransacttrial",connection);
  18.          SqlCommand cmdInsert = TransactDataAdapter.InsertCommand;
  19.          cmdInsert.CommandType = CommandType.StoredProcedure;
  20.         // cmdInsert.Parameters.Add(new SqlParameter("@categoryid", SqlDbType.Int, 50, listCol.));
  21.          cmdInsert.Parameters.Add(new SqlParameter("categoryname", SqlDbType.VarChar, 50, "categoryname"));
  22.          cmdInsert.Parameters.Add(new SqlParameter("@description", SqlDbType.VarChar, 50, "description"));
  23.          cmdInsert.Parameters.Add(new SqlParameter("@amount", SqlDbType.Money, 50,"amount"));
  24.  
  25.         TransactDataAdapter.Update(cDS, "Transact_tabletrialone");
  26.  
  27.  
  28.          // cmdInsert.ExecuteNonQuery();
  29.          // binddatagridview();
  30.  
  31.  
  32.       }
  33.  
  34.  
  35.  
When I try this code, and check my Database , the value "False" is stored in the column description and for the amount 0.0000 is always stored.

Thanks a lot for the help.
-S
Mar 19 '09 #1
Share this Question
Share on Google+
1 Reply

tlhintoq
Expert 2.5K+
P: 3,525
Lots of statements, but no questions.
What is it you are asking of the volunteers here?
Mar 20 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.