Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I already count the column and the index still got an error that my index was out of range, can someone help me please..

C#
var query = "SELECT [tblemployee].[id] ,[tblemployee].[EMP ID], [tblemployee].[FIRST NAME], [tblemployee].[LAST NAME], [tblemployee].[MIDDLE NAME], [tblemployee].[EMAIL], [tblemployee].[EMAIL PASSWORD], [tblemployee].[ADDRESS], [tblemployee].[CONTACT], [tblemployee].[CIVIL STATUS], [tblemployee].[BIRTH DATE], [tblemployee].[BIRTH PLACE], [tblemployee].[EMERGENCY CONTACT], [tblemployee].[USERNAME], [tblemployee].[PASSWORD], [tblempworkinfo].[d_hired], [tblempworkinfo].[d_rate], [tblempworkinfo].DEPARTMENT, [tblempworkinfo].position, [tblempworkinfo].w_status, [tblempworkinfo].w_type FROM[tblemployee] INNER JOIN tblempworkinfo ON tblemployee.[EMP ID]=tblempworkinfo.[EMP ID]";
				_sqlhelper.ViewDatagrid(dgEmployeeList, query);
				switch(msgBoxResult)
				{
					case MessageBoxResult.Yes:
						var row = (DataRowView)dgEmployeeList.SelectedItems[0];
						{
							
							var EditEmployee = new frmAddEmployee
							{
								txtID = { Text = (row["id"]).ToString(), Visibility = Visibility.Hidden },
								txtEmpID = { Text = (row["EMP ID"]).ToString() },
								txtFName = { Text = (row["FIRST NAME"]).ToString() },
								txtLastName = { Text = (row["LAST NAME"]).ToString() },
								txtMname = { Text = (row["MIDDLE NAME"]).ToString() },
								txtEmail = { Text = (row["EMAIL"]).ToString() },
								txtEmailPassword = { Text = row["EMAIL PASSWORD"].ToString() },
								txtAddress = { Text = (row["ADDRESS"]).ToString() },
								txtContacNo = { Text = row["CONTACT"].ToString() },
								cmbStatus = { Text = row["CIVIL STATUS"].ToString() },
								dtpdbirth = { Text = row["BIRTH DATE"].ToString() },
								txtPlaceOfBirth = { Text = row["BIRTH PLACE"].ToString() },
								txtEmergencyNo = { Text = row["EMERGENCY CONTACT"].ToString() },
								txtPassword = { Text = row["password"].ToString() },
								txtUsername = { Text = row["username"].ToString() },
								txtRate = { Text = row["d_rate"].ToString() },
								cmbEmployeeStatus = { Text = row["w_status"].ToString() },
								cmbPosition = { Text = row["position"].ToString() },
								cmbDepartment = { Text = row["DEPARTMENT"].ToString() },
								cmbWorkStatus = { Text = row["w_type"].ToString() },
								dtpdatehired = { Text = row["d_hired"].ToString() },
								btnSave = {Visibility = Visibility.Hidden },
								btnUpdate = { Visibility = Visibility.Visible },
								btnDelete = { Visibility = Visibility.Visible },
								
								Title = "Manage Employee Information",
								//btnSave = { IsEnabled = false },
								//btnDelete = { IsEnabled = false }	
							};


What I have tried:

I already count the column and the index still
Posted
Updated 7-Jan-20 12:43pm
Comments
ZurdoDev 7-Jan-20 15:08pm    
No, no one can help you because no one but you can run the code. But don't worry, it's super simple to fix. Debug it and find out which one is failing and then fix it.

Very simple.

Have you put a breakpoint at
var row = (DataRowView)dgEmployeeList.SelectedItems[0];

and verified that SelectedItems[0] exists? It's difficult to tell, because the error provided is vague, but I would step through the code, and pay particular attention to the above call.
 
Share this answer
 
Comments
Erwin Alcantara 7-Jan-20 18:38pm    
Thanks Kris, I did that but I dont know why is it the im getting 0 in the count, for the selected Items.
Erwin Alcantara 7-Jan-20 18:42pm    
I did figure it out chris.
C#
var query = "SELECT [tblemployee].[id] ,[tblemployee].[EMP ID], [tblemployee].[FIRST NAME], [tblemployee].[LAST NAME], [tblemployee].[MIDDLE NAME], [tblempworkinfo].[NAME], [tblemployee].[EMAIL], [tblemployee].[EMAIL PASSWORD], [tblemployee].[ADDRESS], [tblemployee].[CONTACT], [tblemployee].[CIVIL STATUS], [tblemployee].[BIRTH DATE], [tblemployee].[BIRTH PLACE], [tblemployee].[EMERGENCY CONTACT], [tblemployee].[USERNAME], [tblemployee].[PASSWORD], [tblempworkinfo].[d_hired], [tblempworkinfo].[d_rate], [tblempworkinfo].DEPARTMENT, [tblempworkinfo].position, [tblempworkinfo].w_status, [tblempworkinfo].w_type FROM[tblemployee] INNER JOIN tblempworkinfo ON tblemployee.[EMP ID]=tblempworkinfo.[EMP ID]";
				_sqlhelper.ViewDatagrid(dgEmployeeList, query);
				var msgBoxResult = MessageBox.Show("Modify Employee Information", "Confirmation",
					MessageBoxButton.YesNo, MessageBoxImage.Question);				
				switch(msgBoxResult)
				{
					case MessageBoxResult.Yes:
						var row = (DataRowView)dgEmployeeList.SelectedItems[0];
						{
							
							var EditEmployee = new frmAddEmployee
							{
								txtID = { Text = (row["id"]).ToString(), Visibility = Visibility.Hidden },
								txtEmpID = { Text = (row["EMP ID"]).ToString() },
								txtFName = { Text = (row["FIRST NAME"]).ToString() },
								txtLastName = { Text = (row["LAST NAME"]).ToString() },
								txtMname = { Text = (row["MIDDLE NAME"]).ToString() },
								txtEmail = { Text = (row["EMAIL"]).ToString() },
								txtEmailPassword = { Text = row["EMAIL PASSWORD"].ToString() },
								txtAddress = { Text = (row["ADDRESS"]).ToString() },
								txtContacNo = { Text = row["CONTACT"].ToString() },
								cmbStatus = { Text = row["CIVIL STATUS"].ToString() },
								dtpdbirth = { Text = row["BIRTH DATE"].ToString() },
								txtPlaceOfBirth = { Text = row["BIRTH PLACE"].ToString() },
								txtEmergencyNo = { Text = row["EMERGENCY CONTACT"].ToString() },
								txtPassword = { Text = row["password"].ToString() },
								txtUsername = { Text = row["username"].ToString() },
								txtRate = { Text = row["d_rate"].ToString() },
								txtCompleteName = {Text = row["NAME"].ToString() },
								cmbEmployeeStatus = { Text = row["w_status"].ToString() },
								cmbPosition = { Text = row["position"].ToString() },
								cmbDepartment = { Text = row["DEPARTMENT"].ToString() },
								cmbWorkStatus = { Text = row["w_type"].ToString() },
								dtpdatehired = { Text = row["d_hired"].ToString() },
								btnSave = {Visibility = Visibility.Hidden },
								btnUpdate = { Visibility = Visibility.Visible },
								btnDelete = { Visibility = Visibility.Visible },
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900