title: How to split comma separated values
body: <p>I have text-box inside a gridview and i am performing and insert statement looping through every row in my gridview.  My issue now is that i can have multiple names in the text-box like this: </p>
  
  <pre><code>John Carter, Mike David, John Edward,
  </code></pre>
  
  <p>so how can i split and insert each individual name into my table with the same ID? For instance, if the current row has ID =12 then my table will look like this:</p>
  
  <pre><code>ID      Full_Name
  12     John Carter
  12     Mike David
  12     John Edward
  </code></pre>
  
  <p>here is my code:</p>
  
  <pre><code> foreach (GridViewRow row in GridView1.Rows)
          {
              if (row.RowType == DataControlRowType.DataRow)
              {
                  Label ID = row.FindControl("lbl_ID") as Label;                
                  TextBox myUID = row.FindControl("txt_UID") as TextBox;
                  string Full_Name = Request.Form[row.FindControl("txt_UID").UniqueID];
  
                  SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString);
                  SqlCommand cmd = new SqlCommand();
  
                  cmd.CommandType = CommandType.Text;
                  cmd.CommandText = @"if not exists(select ID from myTable where ID = @ID)
                                     insert into myTable(ID, Full_Name) values(@ID, @Full_Name)
                                      else update myTable set Full_Name =@Full_Name where ID =@ID";
  
                  cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = ID.Text;
                  cmd.Parameters.Add("@Full_Name", SqlDbType.VarChar).Value = Full_Name.ToString();
  
                  cmd.Connection = con;
                  con.Open();
                  cmd.ExecuteNonQuery();
                  con.Close();
  
              }
  }
  </code></pre>