Hello, I want to add multiple pieces of data to the database with only one textbox.
I have a form with SQL Connection, I'm doing a program that upload employees to a site or plant, my idea it's fill with 1 form and in the textbox add more of one employee, here is an example to how should it work if i write employee id.
Example:
employee id (Textbox): 9991, 9992, 8873
Site: US
So when I click on Accept_Button it should save the data in database like this:
Here it's the code I have
HTML:
<div class="item">
<label for="Id">ID<span>*</span></label>
<input id="Id" type="text" runat="server" required="required"/>
`</div>
<div class="item">
<label for="Site">SITE<span>*</span></label>
<input id="Site" type="text" runat="server" required="required"/>
</div>
C#:
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
sqlCon.Open();
string query = "INSERT INTO Employees (EID, Site) VALUES (@EID,@EID)";
SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
sqlCmd.Parameters.AddWithValue("@EID", Id.Value);
sqlCmd.Parameters.AddWithValue("@Site", Site.Value);
sqlCmd.ExecuteNonQuery();
}
I try to use a Split function but I don't know how to add it in my program.
I have this but I don't know how add it or use it:
var sep = new string[] { ", " };
string[] subs = Id.Value.Split(sep, StringSplitOptions.None);