DataGrid headaches

DataGrid populates, but wont edit

Page 1 of 1

2 Replies - 2013 Views - Last Post: 12 September 2007 - 06:29 PM Rate Topic: -----

#1 Misguided  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 02-September 07

DataGrid headaches

Posted 11 September 2007 - 08:37 AM

When I run the code the program runs fine, it allows for the login, and it populates the datagrid with the correct information. However, when I click on the button to edit that row, nothing happens. By the way, the only edit is to remove that person from the team by changing their TeamID to null. This is supposed to remove them from the one datagrid and put them in the other through the dataset called dsMembers1. Here is the section of code that is the problem.


private void dgTeamList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			SqlConnection conn = new SqlConnection ();
			conn.ConnectionString = 
				"integrated security=SSPI;data source=localhost;" +
				"persist security info=False;user=Dana;password=J34iQ198;initial catalog=XYZ Tech Group";
			
			dgTeamList.EditItemIndex = e.Item.ItemIndex;
			int EmpID = Convert.ToInt32(dgTeamList.DataKeys[e.Item.ItemIndex]);
			System.Web.UI.WebControls.TextBox TeamID = new System.Web.UI.WebControls.TextBox(); 
			TeamID = (System.Web.UI.WebControls.TextBox)e.Item.Cells[1].Controls[0]; 
			SqlCommand myCommand = new SqlCommand(); 
			myCommand.CommandText = "UPDATE dsMembers1 SET TeamID = @TeamID WHERE EmpID = @EmpID"; 
			myCommand.Parameters.Add(new SqlParameter("@TeamID",SqlDbType.Int,4)); 
			myCommand.Parameters.Add(new SqlParameter("@EmpID",SqlDbType.Int,4));
			myCommand.Parameters["@EmpID"].Value = EmpID;
			myCommand.Parameters["@TeamID"].Value = null;
 
			conn.Open(); 
			myCommand.ExecuteNonQuery(); 
			conn.Close(); 
			dgTeamList.EditItemIndex = -1;
			dgTeamList.DataBind();
			dgBenched.DataBind();
		}




I know I have everything I am supposed to have but I cannot figure out what I am doing wrong here. Please help.

I ran a test to see if I was getting anything in the variable EmpID and it came back blank, if that helps.

This post has been edited by Misguided: 11 September 2007 - 08:47 AM


Is This A Good Question/Topic? 0
  • +

Replies To: DataGrid headaches

#2 Misguided  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 02-September 07

Re: DataGrid headaches

Posted 12 September 2007 - 06:01 PM

Ok, I did find...correction, my 16 year old nephew found one error that I had. I was putting all this code in the delete event and I had set up the button as a select event. The other thing he caught was that I was calling the server in the connection and yet I was trying to update the dataset. However, after correcting those errors, I am still having the same trouble. The list is not re-populating. I am considering this as NOT solved yet.

Please help me.
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1632
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: DataGrid headaches

Posted 12 September 2007 - 06:29 PM

Misguided,

You can use

myBindingSource.ResetBindings();



This will reset your BindingSource (IF you're using one). You can also try using the GetChanges() Property of dsMembers1, something like


private void dgTeamList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
		   SqlDataAdapter dsTeamList = New SqlDataAdapter;
		   DataSet dsTeamList = New DataSet;
			SqlConnection conn = new SqlConnection ();
			conn.ConnectionString =
				"integrated security=SSPI;data source=localhost;" +
				"persist security info=False;user=Dana;password=J34iQ198;initial catalog=XYZ Tech Group";
			
			dgTeamList.EditItemIndex = e.Item.ItemIndex;
			int EmpID = Convert.ToInt32(dgTeamList.DataKeys[e.Item.ItemIndex]);
			System.Web.UI.WebControls.TextBox TeamID = new System.Web.UI.WebControls.TextBox();
			TeamID = (System.Web.UI.WebControls.TextBox)e.Item.Cells[1].Controls[0];
			SqlCommand myCommand = new SqlCommand();
			myCommand.CommandText = "UPDATE dsMembers1 SET TeamID = @TeamID WHERE EmpID = @EmpID";
			myCommand.Parameters.Add(new SqlParameter("@TeamID",SqlDbType.Int,4));
			myCommand.Parameters.Add(new SqlParameter("@EmpID",SqlDbType.Int,4));
			myCommand.Parameters["@EmpID"].Value = EmpID;
			myCommand.Parameters["@TeamID"].Value = null;

			conn.Open();
			myCommand.ExecuteNonQuery();
			conn.Close();
			dgTeamList.EditItemIndex = -1;
			dsMembers1.GetChanges();   < ----- Try adding this
			dgTeamList.DataBind();
			dgBenched.DataBind();
		}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1