SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 foreach gridviewrows and cells to add in database
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mamor90
Starting Member

Sweden
5 Posts

Posted - 03/23/2013 :  16:43:45  Show Profile  Reply with Quote
i have two textboxes and 1 button that addes the values from the two textboxes in a gridview, now i am trying to
foreach (GridViewRow gvRowAssigment in GridViewAllAssigments.Rows)
// and then cell for cell in the gridview add them to columns in my database like this
var emp_assig_ref = new EMPLOYEES_ASSIGMENT_REFERENCE();
                emp_assig_ref.reference_name = gvRowAssigment.Cells[0].Text;

But i dont gent any values in the columns its empty , what could be the problem?

James K
Flowing Fount of Yak Knowledge

3575 Posts

Posted - 03/23/2013 :  17:13:15  Show Profile  Reply with Quote
Don't know if this is the only problem or not, but you probably need curly braces as shown below in red:
foreach (GridViewRow gvRowAssigment in GridViewAllAssigments.Rows)
{
	// and then cell for cell in the gridview add them to columns in my database like this
	var emp_assig_ref = new EMPLOYEES_ASSIGMENT_REFERENCE();
	emp_assig_ref.reference_name = gvRowAssigment.Cells[0].Text;
}
Go to Top of Page

mamor90
Starting Member

Sweden
5 Posts

Posted - 03/23/2013 :  17:38:55  Show Profile  Reply with Quote
i have it , here u can se hole my code

foreach (GridViewRow gvRowAssigment in GridViewAllAssigments.Rows)
            {
                var emp_assig_ref = new EMPLOYEES_ASSIGMENT_REFERENCE();
                emp_assig_ref.reference_name = gvRowAssigment.Cells.Text;
                emp_assig_ref.reference_id = new Random().Next();

                var emp_assig_teh = new EMPLOYEES_ASSIGMENT_TECHNOLOGY();
                emp_assig_teh.technology_name = gvRowAssigment.Cells[7].Text;
                
                emp_assig_teh.assigment_technology_id = new Random().Next();

                var emp_assig_tools = new EMPLOYEES_ASSIGMENT_TOOLS();
                emp_assig_tools.tools_name = gvRowAssigment.Cells[6].Text;
                emp_assig_tools.assigment_tools_id = new Random().Next();

               
                var emp_assigment = new EMPLOYEES_ASSIGNMENT

                                        {
                                           
                                            from_date = gvRowAssigment.Cells[0].Text,
                                            to_date = gvRowAssigment.Cells[1].Text,
                                            area = gvRowAssigment.Cells[2].Text,
                                            sector = gvRowAssigment.Cells[3].Text,
                                            company_name = gvRowAssigment.Cells[4].Text,
                                            description = gvRowAssigment.Cells[5].Text,

                                            
                                            employee_id = emp.employee_id,
                                            assigment_id = new Random().Next(),
                                            
                                            
                                            EMPLOYEES_ASSIGMENT_TOOLS = emp_assig_tools,

                                            assigment_tools_id = emp_assig_tools.assigment_tools_id,
                                            
                                            EMPLOYEES_ASSIGMENT_TECHNOLOGY = emp_assig_teh,
                                            assigment_technology_id = emp_assig_teh.assigment_technology_id,
                                            
                                            EMPLOYEES_ASSIGMENT_REFERENCE = emp_assig_ref,
                                            reference_id = emp_assig_ref.reference_id

                                        };
                


                emp.EMPLOYEES_ASSIGNMENT.Add(emp_assigment);
 }




            db.AddToEMPLOYEES(emp);
            db.SaveChanges();
        }
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000