Click here to Skip to main content
15,907,676 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
for (int i = 0; i < datagridView.RowCount; i++)
     {
       for (int j = 2; j < datagridView.ColumnCount; j++)
       {
         if (datagridView[j, i].Value.ToString().Contains(","))
         {           
           string strvalue = datagridView[j, i].Value.ToString() + ", " + cb_Course.Text;
           string[] strarray = strvalue.Split('/');
           foreach(object obj in strarray)
           {
           //in that my insert query         
           }
         }
       }
     }


when i run the above code and save in the database.

record not saving what is the problem in my above code


My insert query as follows;

C#
sql = "insert into Tb_SCh_TIme_Table([Sch_Date], [Session], [Course],[Faculty_Code])" + " values ('" + Convert.ToDateTime(datagridView.Rows[i].Cells[0].Value.ToString()) + "', " + int.Parse(datagridView.Rows[i].Cells[1].Value.ToString()) + ", '" + datagridView[j, i].Value.ToString() + "','" + datagridView.Columns[j].HeaderText.ToString() + "')";



what is the problem in my code , when i run in the datagridview two values are there in a cell as follows

REO,MFA

i want to split and save in the database.
Posted
Updated 28-Feb-13 18:40pm
v3
Comments
willington.d 28-Feb-13 23:51pm    
run the code with breakpoint and post what is the error...
Babu Kumar 1-Mar-13 0:44am    
Hi,,
Check the code
string[] strarray = strvalue.Split('/');
instead of this u need to use
string[] strarray = strvalue.Split(',');
because you want to split with comma right?

If anything further required, Let us know.

Regards,
Babu.K

1 solution

you have to use Split(',') instead of Split('/')
 
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