locked
Help with a data fill with textbox RRS feed

  • Question

  • User196874992 posted

    Hello, 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, like:

    employee id: 9991, 9992, 8873... 

    So in the database i can saw something like this:

    Employee Site
    9991 US
    9992 US

    This it's the form:

    https://prnt.sc/13fyg1v

    form1

    Wednesday, May 26, 2021 2:41 PM

All replies

  • User-939850651 posted

    Hi EvansGxz,

    According to your description, do you want to use the search button to query data based on the options the user has selected, and then show the IDs in the TextBox?

    If this is the case, you could refer this simple demo:

    <body>
        <form id="form1" runat="server">
            <div>
                <br />
                Employee ID(s): <asp:TextBox runat="server" Width="300px" Enabled="false" ID="idsBox" /> 
                <asp:Button Text="Search" ID="searchBtn" runat="server" OnClick="searchBtn_Click" />
                <br />
                <br />
                Site/Plant:<asp:DropDownList runat="server" ID="SiteDDL">
                    <asp:ListItem Text="USA Dallas CSC" Value="US" />
                    <asp:ListItem Text="Other" Value="Other"/>
                </asp:DropDownList>
            </div>
        </form>
    </body>
    public static DataTable dt;
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack) {
                    dt = new DataTable();
                    dt.Columns.AddRange(new DataColumn[] {
                        new DataColumn("ID"),
                        new DataColumn("Site")
                    });
                    dt.Rows.Add("E000377584","US");
                    dt.Rows.Add("E000314XXX","US");
                    dt.Rows.Add("E000XXXXXX","Other");
                    dt.Rows.Add("E000XXX000","Other");
                }
            }
    
            protected void searchBtn_Click(object sender, EventArgs e)
            {
                string idsBoxText = string.Empty;
                //get BoxText based on site dropdown selected value
                string selectSite = SiteDDL.SelectedItem.Value;
                DataRow[] dataRows = dt.Select("Site = '"+ selectSite + "'");
                foreach (DataRow row in dataRows) {
                    idsBoxText += row.Field<string>("ID")+",";
                }
                idsBoxText = idsBoxText.Substring(0,idsBoxText.Length-1);
    
                idsBox.Text = idsBoxText;
            }

    Result:

    If I misunderstood anything, could you describe your problem in more detail?

    Best regards,

    Xudong Peng

    Thursday, May 27, 2021 2:58 AM
  • User196874992 posted

    Search its to verify, it migth be in the bottom a "save" button to register that data.

    When I click in the search button, it should appear a window like this:

    https://prnt.sc/13h9t3q

    Here I can verify if the employee exist, if exist then I can do click on Accept button, then I add it, that its the easy step

    The step i don't know how to do it's how save the data for all employee I select, the idea it's, like the exampe, if I add 1 id, save that id with the site in SQL, but if I have more of one, like 10, 20, 50 employe ID in the TextBox, save the site I select for all.

    Also thanks for your answer, respectfully yours.

     

    Thursday, May 27, 2021 1:04 PM
  • User-939850651 posted

    Hi EvansGxz,

    The step i don't know how to do it's how save the data for all employee I select, the idea it's, like the exampe, if I add 1 id, save that id with the site in SQL, but if I have more of one, like 10, 20, 50 employe ID in the TextBox, save the site I select for all.

    According to your description, your main question is how to add multiple pieces of data to the database?

    If this is the case, you could use the String.Split() method to get all IDs from TextBox, and then use a loop to traverse the IDs and insert them one by one into the data table. In each traversal, you only need to update the parameters that need to be inserted.

    Best regards,

    Xudong Peng

    Friday, May 28, 2021 3:04 AM