I am Working on Conecting to a database in windos forms C++. I use MVC++.

here is a link to my DB file so people can see what i have tried to do in the DB.

http://www.mediafire.com/?yfr52oqcknakk9g

you need access to see this.

i have finaly figured out how to make a connection to the database and put a table into a dataset and then put the data in the dataset into a combobox however what i dont know how to do is limit the data put in the combobox.

right not i have 3 combobox one called gravity another called temperature and my last one is called climate. there is 3 things i want to do. I want to take the data and put the text in the box (i can do that) but i want to limite what is put in there. I want it to put Heavy, Normal and Low into one combobox. Gas, Nox, Terran in another one and then the last 3 in the last box. i have put in the table all heavy type == 0 all temp type == 1 all climate type == 2.

i also have a thing called addonholder. i want that number to be stored with that text. so if someone was to selection Heavy, Terran, Frozen. it will look at the addonholder colume and times them togeather. to give you an output.

I am finging it hard to do this. I was origonly do this hard coded but decided to put it all into a database and slowing working through it all hehe :).

There is one other thing aswell. I want to be able to look at to tables I have put stuff in the database so it can link easier. I have another 6 boxes on my form so when heavy is seleted it will added in the terraforming section the same option in all 6 boxes. but when someone selects that option it will remove it from all the boxes and then added a new lvl to the boxes.

here is how i have coded the conection and the inserting to the combobox.

private:
		OleDbConnection^ myConnection;

	public:
		CAadvanced(void)
		{
			InitializeComponent();
			myConnection = gcnew OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Jordan\\Documents\\Star Sonata\\CA_Data.mdb;Persist Security Info=False");
			
			DataSet^ cadata = gcnew DataSet();

			connectionOpen();
			OleDbDataAdapter^ data = gcnew OleDbDataAdapter("SELECT t_planet_props.* FROM t_planet_props;", myConnection);
			data->Fill(cadata);
			connectionClose();

			this->Temp->DataSource = cadata->Tables[0];
			this->Temp->DisplayMember = "name";

			//TODO: Add the constructor code here
			//
		}

Recommended Answers

All 4 Replies

When you do your query, do you get back 3 result rows or 9 result rows? If you are getting 9, you should be able to use the value in the "l_type" column to differentiate the rows. Create a for loop that returns the row result if the value of l_type is correct for the combo box. I'm not overly familiar with WinForms, but I suspect you could probably do it with add commands inside a switch of some sort in the form::onDisplay() function.

Personally, I would do it as 3 individual queries then use the individual returns to populate each one. Something like " SELECT * FROM t_planet_props WHERE l_type = [B][I]aValue[/I][/B] ". For this to work well though, you would probably have to add an index to the "l_type" column, it doesn't appear to be indexed currently.

commented: thanks for the help :) +0

9 i am wanting to split that up into 3 parts givng me 3 bits of info for each

Overlapped while editing, please review my previous post...

thanks ill try and get stuff to wrok from what you said

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.