473,388 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

How to get the selected item in the Combobox and Textbox

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
1 5197
tlhintoq
3,525 Expert 2GB
Lots of statements, but no questions.
What is it you are asking of the volunteers here?
Mar 20 '09 #2

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

Similar topics

8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
2
by: farseer | last post by:
Hi, I have a combobox who's data source i set to an array of objects (call it MyObject). these objects have get properties: key, value, descr. i set ValueMember to "key", DisplayMember to...
1
by: tupolev | last post by:
I have successfully created a datagrid with a combobox added in a column of the datagrid, I also have written an event that works when you select an other item in the combobox. Know: how can I...
2
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a...
2
by: minu | last post by:
Hello all I am beginner to VB I populate all the professers name in one combobox ,If i select one professer name then thier designation will automatically display in textbox from database field ...
9
by: Franky | last post by:
I have a usercontrol that inherits from ComboBox I'd like to add the feature that the user can delete any item Best would be that he could right click an element and a messagebox would ask if...
1
by: soniyaa | last post by:
hi every one, well i have a small doubt when ever i select the item in the combobox it should be diaplayed in the textbox. plz help meee
1
by: vishnu2008 | last post by:
Hi, I have a combobox with some comments in it .when we select any one item in combobox all the items should be displayed in textbox. please help me with code. Thanks
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.