|
Hi everyone, I downloaded the DataRepeater but now stuck and need your help in VS2005. On windows form how do i filter the records for each employee. Inside the datarepeater i want to display the Employee_ID then Employee_Name and fill the Datagridview with all her/his leave details. For example in my table i have these cloumns:-
EMP_ID EMP_Name EMP_Leave _____________________________________________________________ 001 Rebecca SICK 002 Sara ANNUAL 003 Rebecca SHORT 004 Rebecca SICK 005 Sara SHORT
Inside the Datarepeater i have placed TWO LABELS and A DATAGRIDVIEW.
FIRST LABEL FOR EMPLOYEE_ID SECOND LABEL FOR EMPLOYEE_NAME DATAGRIDVIEW 'TO FILTER AND DISPLAY ALL LEAVES TAKEN BY THE EMPLOYEE
Private _emptable As DataTable = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Cursor = Cursors.WaitCursor
Try _emptable = Employees.EmployeesData().Tables(0)
Labe1.DataBindings.Add("Text", _emptable, "Employee_ID") Labe2.DataBindings.Add("Text", _emptable, "Employee_Name") DataGridView1.DataSource = _emptable ' MAYBE NEED FILTERING HERE
DataRepeater1.DataSource = _emptable
Catch ex As Exception MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try
Me.Cursor = Cursors.Default
End Sub
Private Sub DataRepeater1_DrawItem(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs) Handles DataRepeater1.DrawItem
If e.DataRepeaterItem.ItemIndex Mod 2 = 0 Then e.DataRepeaterItem.BackColor = Color.FromArgb(213, 224, 211) Else e.DataRepeaterItem.BackColor = SystemColors.Control End If
End Sub
Public Class Employees
Private Shared _con As OleDbConnection = Nothing Private Shared _com As OleDbCommand = Nothing Private Shared _dap As OleDbDataAdapter = Nothing Private Shared _dset As DataSet = Nothing
Private Shared _sqlstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=..\EMPLOYEEDETAILS.mdb"
Public Shared Function EmployeesData() As DataSet
Try _con = New OleDbConnection(_sqlstr) _con.Open()
_com = New OleDbCommand() With _com .Connection = _con
.CommandType = CommandType.Text
.CommandText = "SELECT Employee_ID, Employee_Name, Employee_Leave FROM Employees" End With
_dap = New OleDbDataAdapter(_com) _dset = New DataSet("DSetEmployees") _dap.Fill(_dset)
Catch ex As Exception _dset = Nothing Throw ex End Try
Return _dset
End Function End Class END CLASS
Any Suggestions!! At the moment it wroks fin but the problem is with Datagridview. It displays all records for every employee. But i need is to filter records in the datagridview for each employee based on their ID.
Thanx a ZILLION!!1 irfi - Changed TypeVSIRFI Saturday, October 10, 2009 2:38 PM
-
| | VSIRFI Saturday, October 10, 2009 11:15 AM | the editor is not cooperating. here is the sample with the important items highlighted _emptable = Employees.EmployeesData( Me.Labe1.Text).Tables(0) Public Shared Function EmployeesData( ByVal idval As String) As DataSet With _com .Connection = _con .CommandType = CommandType.Text .CommandText = "SELECT Employee_ID, Employee_Name, Employee_Leave FROM Employees WHERE Employee_ID = @val" .Parameters.AddWithValue("@val", idval) End With FREE DEVELOPER TOOLS, CODE & PROJECTS at www.srsoft.us Database Code Generator and Tutorial- Marked As Answer byJeff ShanMSFT, ModeratorThursday, October 15, 2009 6:16 AM
-
| | Jeff - www.SRSoft.us Saturday, October 10, 2009 5:48 PM | Public Shared Function EmployeesData(ByVal idval As String) As DataSet
you need to set your idval to something like:
idval="20" the reason why its not showing anything its because is empety
Try
_con = New OleDbConnection(_sqlstr)
_con.Open()
_com = New OleDbCommand()
With _com
.Connection = _con
.CommandType = CommandType.Text
.CommandText = "SELECT Employee_ID, Employee_Name, Employee_Leave FROM Employees WHERE Employee_ID = @val" .Parameters.AddWithValue("@val", idval)
End With
_dap = New OleDbDataAdapter(_com)
_dset = New DataSet("DSetEmployees")
_dap.Fill(_dset)
Catch ex As Exception
_dset = Nothing
Throw ex
End Try
Return _dset
End Function
End Class
End Class
Don't judge me, just Upgrade me. Thanks! - Marked As Answer byJeff ShanMSFT, ModeratorThursday, October 15, 2009 6:16 AM
-
| | Malange Sunday, October 11, 2009 4:39 PM | This is not a discussion, change your thread type to question by click on change type
kaymaf I hope this helps, if that is what you want, just mark it as answer so that we can move on
| | kaymaf Saturday, October 10, 2009 1:08 PM | .CommandText = "SELECT Employee_ID, Employee_Name, Employee_Leave FROM Employees WHERE Employee_ID = @val" .parameters.addwithvalue("@val", Labe1.text)
FREE DEVELOPER TOOLS, CODE & PROJECTS at www.srsoft.us Database Code Generator and Tutorial | | Jeff - www.SRSoft.us Saturday, October 10, 2009 1:38 PM | Thank you Jeff for your reply,
if i replace your code i get the error
.CommandText = "SELECT Employee_ID, Employee_Name, Employee_Leave FROM Employees WHERE Employee_ID = @val" .parameters.addwithvalue("@val", Labe1.text)
Error 1 Parameter is not a member of string Error 2 Reference to a non-shared member requires an object reference. (Under label1.text)
I add "&" and Error 1 is fixed
.CommandText = "SELECT Employee_ID, Employee_Name, Employee_Leave FROM Employees WHERE Employee_ID = @val" & .parameters.addwithvalue("@val", Labe1.text)
But i still get error 2 under label1
Any suggestions.
thank you irfi
| | VSIRFI Saturday, October 10, 2009 3:29 PM | update these lines like this and try it
_emptable = Employees.EmployeesData(Me.Labe1.Text).Tables(0)
Public Shared Function EmployeesData(ByVal idval As String) As DataSet
With _com .Connection = _con .CommandType = CommandType.Text .CommandText = "SELECT Employee_ID, Employee_Name, Employee_Leave FROM Employees WHERE Employee_ID = @val" .Parameters.AddWithValue("@val", idval) End With
i don't know what your employee id data type is so you can adjust that in the employeesdata declaration for idval. you would need to convert the text to the propert type for me.labe1.text in the first line in this post. | | Jeff - www.SRSoft.us Saturday, October 10, 2009 5:42 PM | the editor is not cooperating. here is the sample with the important items highlighted _emptable = Employees.EmployeesData( Me.Labe1.Text).Tables(0) Public Shared Function EmployeesData( ByVal idval As String) As DataSet With _com .Connection = _con .CommandType = CommandType.Text .CommandText = "SELECT Employee_ID, Employee_Name, Employee_Leave FROM Employees WHERE Employee_ID = @val" .Parameters.AddWithValue("@val", idval) End With FREE DEVELOPER TOOLS, CODE & PROJECTS at www.srsoft.us Database Code Generator and Tutorial- Marked As Answer byJeff ShanMSFT, ModeratorThursday, October 15, 2009 6:16 AM
-
| | Jeff - www.SRSoft.us Saturday, October 10, 2009 5:48 PM | Thanx again Jeff for your help!!
I tried your code and now no more errors!
But sadly when i run the form nothing appears! The form just show the border of datarepeater and nothing else. It doesn't show the controls as well as no data.
The data type of employee_Id is number and field size is integer in my access table.
I know with your help i am almost there........ but cannot guess what may be the likely cause.
Again need your help!!!
This is my FINAL CODE WHICH I UPDATED AS PER YOUR HELP FROM YOUR PREVIOUS POST.
Public Class Form3
Private _emptable As DataTable = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Cursor = Cursors.WaitCursor
Try
' _emptable = Employees.EmployeesData().Tables(0)
_emptable = Employees.EmployeesData(Me.Label1.Text).Tables(0)
Label1.DataBindings.Add("Text", _emptable, "Employee_ID")
Label2.DataBindings.Add("Text", _emptable, "Employee_Name")
DataGridView1.DataSource = _emptable
DataRepeater1.DataSource = _emptable
Catch ex As Exception
MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Me.Cursor = Cursors.Default
End Sub
Private Sub DataRepeater1_DrawItem(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs) Handles DataRepeater1.DrawItem
If e.DataRepeaterItem.ItemIndex Mod 2 = 0 Then
e.DataRepeaterItem.BackColor = Color.FromArgb(213, 224, 211)
Else
e.DataRepeaterItem.BackColor = SystemColors.Control
End If
End Sub
Public Class Employees
Private Shared _con As OleDbConnection = Nothing
Private Shared _com As OleDbCommand = Nothing
Private Shared _dap As OleDbDataAdapter = Nothing
Private Shared _dset As DataSet = Nothing
Private Shared _sqlstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=..\EMPLOYEEDETAILS.mdb"
' Public Shared Function EmployeesData() As DataSet
Public Shared Function EmployeesData(ByVal idval As String) As DataSet
Try
_con = New OleDbConnection(_sqlstr)
_con.Open()
_com = New OleDbCommand()
With _com
.Connection = _con
.CommandType = CommandType.Text
.CommandText = "SELECT Employee_ID, Employee_Name, Employee_Leave FROM Employees WHERE Employee_ID = @val" .Parameters.AddWithValue("@val", idval)
End With
_dap = New OleDbDataAdapter(_com)
_dset = New DataSet("DSetEmployees")
_dap.Fill(_dset)
Catch ex As Exception
_dset = Nothing
Throw ex
End Try
Return _dset
End Function
End Class
End Class
| | VSIRFI Saturday, October 10, 2009 9:15 PM | Public Shared Function EmployeesData(ByVal idval As String) As DataSet
you need to set your idval to something like:
idval="20" the reason why its not showing anything its because is empety
Try
_con = New OleDbConnection(_sqlstr)
_con.Open()
_com = New OleDbCommand()
With _com
.Connection = _con
.CommandType = CommandType.Text
.CommandText = "SELECT Employee_ID, Employee_Name, Employee_Leave FROM Employees WHERE Employee_ID = @val" .Parameters.AddWithValue("@val", idval)
End With
_dap = New OleDbDataAdapter(_com)
_dset = New DataSet("DSetEmployees")
_dap.Fill(_dset)
Catch ex As Exception
_dset = Nothing
Throw ex
End Try
Return _dset
End Function
End Class
End Class
Don't judge me, just Upgrade me. Thanks! - Marked As Answer byJeff ShanMSFT, ModeratorThursday, October 15, 2009 6:16 AM
-
| | Malange Sunday, October 11, 2009 4:39 PM | This my view point....you do not need it :Private _emptable As DataTable = Nothing
you should use Bindingsource.....
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Cursor = Cursors.WaitCursor
Try
' _emptable = Employees.EmployeesData().Tables(0)
_emptable = Employees.EmployeesData(Me.Label1.Text).Tables(0)
Label1.DataBindings.Add("Text", _emptable, "Employee_ID")
Label2.DataBindings.Add("Text", _emptable, "Employee_Name")
DataGridView1.DataSource = _emptable
DataRepeater1.DataSource = _emptable
Catch ex As Exception
MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Me.Cursor = Cursors.Default
End Sub
I would to this way:
Using loveme As New OleDbConnection(StrCnn)
Dim commandme As New OleDbCommand("Select * from Employer ORDER BY ID ", loveme)
loveme.Open()
Dim reademe As OleDbDataReader = commandme.ExecuteReader()
Dim ligame As New BindingSource ligame.DataSource = reademe
Label1.DataBindings.Add("Text", ligame, "Employee_ID")
Label2.DataBindings.Add("Text", ligame, "Employee_Name") Me
.DataGridView1.DataSource = ligame
reademe.Close()
End Using
Don't judge me, just Upgrade me. Thanks! | | Malange Sunday, October 11, 2009 4:40 PM | Thank you very much Malange.
I was having problem with my inet connection and couldn't come back to the forums.
As you mentioned idval="20" where do i have to declare this. I tried the way you posted but still no results and datarepeater control is still empty.
Anymore suggestions, Please.
Cheers | | VSIRFI Thursday, October 15, 2009 6:38 AM |
Thank you very much Malange.
I was having problem with my inet connection and couldn't come back to the forums.
As you mentioned idval="20" where do i have to declare this. I tried the way you posted but still no results and datarepeater control is still empty.
Anymore suggestions, Please.
Cheers
you declare it inside your function or at the top of your form Dim IDVAL As String
Don't judge me, just Upgrade me. Thanks! | | Malange Thursday, October 15, 2009 7:27 PM | Thanx again Malange,
I tried and only if i declare like idval="001" which is the employee ID for one of the employees it shows the records for this particular employee.
If i dont declare idval then it displays value cannot be null.
What i am trying is to show the employee_id in the label and their leave records in the datagridview and repeat for each employee inside each item template of the datarepeater.
Is this possible in the first place?? I mean during runtime fill the datagridview with the value from Label1.text.
need help!!! Thanx
| | VSIRFI Thursday, October 15, 2009 8:53 PM | Thanx again Malange,
I tried and only if i declare like idval="001" which is the employee ID for one of the employees it shows the records for this particular employee.
If i dont declare idval then it displays value cannot be null.
What i am trying is to show the employee_id in the label and their leave records in the datagridview and repeat for each employee inside each item template of the datarepeater.
Is this possible in the first place?? I mean during runtime fill the datagridview with the value from Label1.text.
need help!!! Thanx
Do it please in your function Dim IDVAL As String= inputBox("Type Employees ID Please?", "Employees ID", "0000") if IDVAL = "" Then Msgbox("For you to find Employees ID you need to type the ID") else ...................write the rest of the code here .................... ................... ............... End if
Don't judge me, just Upgrade me. Thanks! | | Malange Thursday, October 15, 2009 9:11 PM | Dear Malange, I don't want to use any sort of input box.
I want to get all the Employee_ID and their Leave_Records during runtime and display them in the item_template of datarepeater.
This is how i assume it would look like inside the datarepeater when i load the form.
______________________________________________________________________________________ ' Item_Template Employee_ID: 001 ' Id displayed in Label1
--------------------------------------------------- LEAVE RECORDS ' Datagridview --------------------------------------------------- Sick Annual --------------------------------------------------- _____________________________________________________________________________________ Employee_ID: 002
--------------------------------------------------- LEAVE RECORDS --------------------------------------------------- Short Annual --------------------------------------------------- ___________________________________________________________________________________ Employee_ID: 003
--------------------------------------------------- LEAVE RECORDS --------------------------------------------------- Short --------------------------------------------------- ____________________________________________________________________________________
Is it possible to achieve it this way... or simply i am wasting your time. Any more help!!!! Cheers
| | VSIRFI Friday, October 16, 2009 11:00 AM | Most people are having problem with DataR.Dataspource, they cannot fecth information to it, for some reason... I try to do it as well to solve your problem, and I couldnt...Why, I dont know, have a look here please:
http://www.bigresource.com/VB-dataRepeater-datasource-rRmcDMDQNV.html
Don't judge me, just Upgrade me. Thanks! | | Malange Friday, October 16, 2009 1:11 PM | | | Malange Friday, October 16, 2009 1:14 PM | Hi Malange, Thanx for your reply and I appreciate your time spent in sloving my problem. Since both of us are still struggling to get the desired output, how about trying a different approach. So far Employee_Id is displayed for each employee in Label1.text - NO PROBS!!! Secondly, the datagridview control also fetches the Leave_records..BUT Unfortunately for all the employees. It doesn't filter them.
Now all that we are trying to get is to make the datagridview filter and display the leave records for each employee corresponding to the id displayed inside the label1.text.... FINE..
HOw about if we tried to hide rows in the datagridview.... I mean for each datagridview inside the datarepeater lets try and hide the rows and display only those rows that match the employee_Id in the corresponding label1.text and repeat this for every datagrdiview.
What do you think does my idea make any sense???
Cheers
| | VSIRFI Friday, October 16, 2009 3:10 PM | Sorry to say that but you are confusing me...do want to display in your DVG the ID only? do it :
Using
con As New OleDbConnection(cnn)
Dim name As New OleDbCommand("Select * From Table1 Where Employees_ID=@Employees_ID", con)
'name.Parameters.AddWithValue(
"@Employees_ID", Me.label1.text)
con.Open()
Dim reader As OleDbDataReader = name.ExecuteReader()
With reader Me.Bindingsource.Datasource=reader Me.DVG.datasource=Bindingsource ' this will show the all Employees ID in your DGV and nothing else End With
If you want to Hide something from your DGV do it: Me.DataGridView1.Columns.Remove("Name") that remove the columns name.....from your DGV.
Am wordering, label control is not input control....you cannot type any thing there but asign it....
Don't judge me, just Upgrade me. Thanks! | | Malange Friday, October 16, 2009 3:22 PM | IS YOUR datarepeater WORKING FINE? SHOW ME HOW YOU DID THAT PLEASE?
Don't judge me, just Upgrade me. Thanks! | | Malange Friday, October 16, 2009 3:24 PM | Pleasesee the code in my very first post..right on top it is working and the only problem i am facing is again DGV filtering.
Employee_ID and Employee_Name are displayed in label1.text and label2.text. Leave_Records are displayed in DGV but sadly for all employees. I want filter the records in DGV accroding to the Employee_ID.
With the code in my first post i can achieve this.
______________________________________________________________________________________ ' Item_Template Employee_ID: 001' Id displayed in Label1 Employee_Name: Sarah Jonson 'Name displayed in Label2
--------------------------------------------------- EMPLOYEE_ID LEAVE_RECORDS ' DGVit fills all employees leave records --------------------------------------------------- 001Sick' SHOULD ONLY DISPLAY LEAVE RECORDS FOR EMPLOYEE_ID 001 001Short 002Annual 003Short --------------------------------------------------- _____________________________________________________________________________________ Employee_ID: 002' Id displayed in Label1 Employee_Name:Simon Cowell 'Name displayed in Label2
--------------------------------------------------- EMPLOYEE_ID LEAVE_RECORDS'DGV - Again it displays all leave records --------------------------------------------------- 001Sick 001Short 002Annual ' SHOULD ONLY DISPLAY LEAVE RECORDS FOR EMPLOYEE_ID 002 003Short --------------------------------------------------- _____________________________________________________________________________________ Employee_ID: 003' Id displayed in Label1 Employee_Name:Mitchelle Young 'Name displayed in Label2
--------------------------------------------------- EMPLOYEE_ID LEAVE_RECORDS'DGV - AND Again it displays all leave recods --------------------------------------------------- 001 Sick 001 Short 002Annual 003 Short ' SHOULD ONLY DISPLAY LEAVE RECORDS FOR EMPLOYEE_ID 003 --------------------------------------------------- _____________________________________________________________________________________
I have hidden the Employee_Name Column from the DGV..butforgot tomention the code for that in my first post Hope this now explains better to what i am trying to achieve. Thanx - Edited byVSIRFI Saturday, October 17, 2009 8:03 AM
-
| | VSIRFI Friday, October 16, 2009 8:13 PM | Sorry was my mistake I should look at your code, I solved your problem...
Dim
mydaaset As New DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Users/Gift from above/Documents/oledb_Teste/Copy of LMS_Backup2.mdb"
Dim ok As String = "Select * from STUDENT ORDER BY ID"
Using con As New OleDbConnection(connectionString)
Dim name As New OleDbDataAdapter(ok, con)
mydaaset.Tables.Add("STUDENT")
name.Fill(mydaaset.Tables(
"STUDENT"))
MeBindingSource.DataSource = (mydaaset.Tables(
"STUDENT"))
Me.Label1.DataBindings.Add("Text", BindingSource, "ID", True)
Me.Label2.DataBindings.Add("Text", BindingSource, "FirstName", True)
Me.DataGridView1.DataSource = BindingSource
now hide or remove it from your DGV.
me.DatagridView1.Column.Remove("ID") me.DatagridView1.Column.Remove("FirstName")
End
Using
Don't judge me, just Upgrade me. Thanks! | | Malange Friday, October 16, 2009 8:48 PM | Use this one please have you gonna have idea of your solution....
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Users/Gift from above/Documents/oledb_Teste/Copy of LMS_Backup2.mdb" Using loveme As New OleDbConnection(connectionString) Dim commandme As New OleDbCommand("Select * from STUDENT Where ID=@ID", loveme) commandme.Parameters.AddWithValue("@ID", Me.ComboBox1.Text) loveme.Open() Dim reademe As OleDbDataReader = commandme.ExecuteReader() Dim ligame As New BindingSource ligame.DataSource = reademe For Each Ctl As Control In Me.Controls If TypeOf Ctl Is DataGrid Then Ctl.DataBindings.Clear()
End If
Next Me.DataGridView1.DataSource = ligame End Using
End Sub
Don't judge me, just Upgrade me. Thanks!
reademe.Close()
- Edited byMalange Sunday, October 18, 2009 7:59 PM
-
| | Malange Friday, October 16, 2009 9:20 PM |
Dim
mydaaset As New DataSet
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Users/Gift from above/Documents/oledb_Teste/Copy of LMS_Backup2.mdb"
Dim ok As String = "Select * from STUDENT ORDER BY ID"
Using con As New OleDbConnection(connectionString)
Dim name As New OleDbDataAdapter(ok, con)
mydaaset.Tables.Add("STUDENT")
name.Fill(mydaaset.Tables(
"STUDENT"))
MeBindingSource.DataSource = (mydaaset.Tables(
"STUDENT"))
Me.Label1.DataBindings.Add("Text", BindingSource, "ID", True)
Me.Label2.DataBindings.Add("Text", BindingSource, "FirstName", True)
Me.DataGridView1.DataSource = BindingSource
now hide or remove it from your DGV.
me.DatagridView1.Column.Remove("ID")
me.DatagridView1.Column.Remove("FirstName")
End
Using
Dear Malange you think your above code has solved the problem. Ok tell me where are you filtering the DGV to display leave_records of employees corresponding to their EMPLOYEE_ID in LABEL1.TEXT as i have clearly shown in my last post and repeat this step for each employee in the datarepeater. Secondly, Where have you declared the datasource for the DATAREPEATER. Come on now iam confused!!!! Please have a look again at my last post. I appreciate all your help but pls do come back with your suggestions. Thank you
| | VSIRFI Saturday, October 17, 2009 8:04 AM |
|