Displaying the Data and deleting the selected one.

gloringg

Member
Joined
Jan 11, 2009
Messages
16
Programming Experience
Beginner
Hi,

I need some help.

Please see Image Below......

http://i44.tinypic.com/25slyev.jpg

Apologies if i am not supposed to paste external links, but just wanted to share the concept clearly.

In the picture, I have department and listbox.

Now, I have a Table name - "Company_Data" with the Columns

Name|Age|Department|Salary

All I want is when i select the department in the drop down, the list should show all the names under the department.

Also, when i select the name in the list and click delete. IT should delete the complete record from the Table.

Can anyone please tell me how to do this.......

The Sample code would be of great help.

Thanks,
 
Anything like this would be of great help.

Hi,

Anything like this would be of great help.


263fqxc.jpg



Please let me know what i need to do.
Dont have much time to finish my project.

Thanks.
 
Read the DW2 link in my signature, first read the section Creating a Simple Data App, then read Creating a Form To Search Data
 
That sounds like an homework... hehe :p

Don't bind the DataGridView directly to the DataSet's Company_Data DataTable. Create a DataView from the DataTable and set it to the DataGridView's DataSource property.

Now, use the designer to bind the ComboBox's DataSource to the list of departments. I understand that the departments are not in a separate table using a foreign key. You might want to change that. In any case, react to the SeletectedIndexChanged event on the combo box to set the Dataview's Filter property to something like :

companyDataView.Filter = "Department = " + myComboBox.SelectedItem.ToString()

Or if you do use a foreign key, set the combo box's ValueMember and DisplayMember properties right and use the combo box's SelectedValue property instead of SelectedItem.

That's a lot of technical term and I'm sorry, you should try a tutorial on DataBinding
 
That sounds like an homework... hehe :p

Don't bind the DataGridView directly to the DataSet's Company_Data DataTable.

They don't anyway; datatables have a .DefaultView which returns a default unfiltered DataView to which the datagridview will bind. You can call myDT.DefaultView.Filter = "..." to filter a grid that you bound using:

myDGV.DataSource = myDT
 
thanks

thanks for your reply.

Is there any possible where i can find some sample files or else some video tutorials on this.

I am really new to this and have got no knowlege on it and i think the easiest way to understand and do is by videos or sample files.

Thanks again!!
 
Follow the DW2 link in my signature, section Creating A Simple Data App.

Use the debugger and the IDE to explore what a DataTable, DataSet, TableAdapter etc is..
 
please correct this code

con = New OleDbConnection("Provider=Microsoft.JET.OLEDB.4.0;Data Source=ABC.mdb")


cmd = New OleDbCommand("Select * from [Company_Data] where [Department] = '" & ComboBox1.Text & "'", con)

After this i thing i need to create a data set and copy the data to datagrid, something i am missing......then

Try

cmd.Connection.Open()

cmd.ExecuteNonQuery()

I need to fill the dataset to the datagrid here........



Me.Company_dataTableAdapter.Fill(Me.ABC1.Company_Data)

Catch myException As Exception
MsgBox(": " + myException.ToString())
Finally
cmd.Connection.Close()
End Try



Can you please correct this for me.

The Datagrid is actually displaying the whole list now, but i want it to display only the filtered data.



Thanks,
 
Me.ABC1.Company_Data.DefaultView is the DataView used by your DataGridView. That's the object you will use to filter data.

See this for more information about DataViews : DataView Class (System.Data)

and this is about the RowFilter property you will need. The syntax is a bit like SQL : DataView.RowFilter Property (System.Data)

By the way, you are using .NET3.5 so you can use LINQ in all this. I don't know much about it because I use .NET2.0 (waiting to see which technologies get deprecated before I spend time learning them seems like a viable strategy ;)) so it's really up to you
 
Can you please correct this for me.
Sure. Read the DW2 link like I told you twice already, and you can get VIsual Studio to write the code for you. Advantage is, when it writes it: It's good, and it works

The Datagrid is actually displaying the whole list now, but i want it to display only the filtered data.

myDataTable.DefaultView.Filter = "BLAH BLAH"
 
Can you please correct this for me.
Sure. Read the DW2 link like I told you twice already, and you can get VIsual Studio to write the code for you. Advantage is, when it writes it: It's good, and it works

The Datagrid is actually displaying the whole list now, but i want it to display only the filtered data.

Me.ABC1.Company_Data.DefaultView.Filter = "BLAH BLAH"
 

Latest posts

Back
Top