Hi guys need your helps. Now i doing the update part for my program. How to i get data from two table after i type the badge id and employee id then i will show other detail in the same form. So how to do that, need to use what method on it. need what sql?

Other question is how to move the data form table 1 to table 2 after the user update the data. Like active = yes table1 and active=no table two ? Need to do what in the sql statement?

Dani AI

Generated

Building on the hints from and , here is a practical, safe pattern to (A) load details for a given badge id + employee id and (B) either mark a record inactive or move it to an archive table. Use parameterized SQL (stored procedures or parameterized commands) and a single query that returns all fields you need from both tables. That keeps UI code simple and avoids SQL injection.

Example stored procedure to fetch one row (adjust column/table names to your schema):

CREATE PROCEDURE GetEmployeeDetails
  @BadgeId  NVARCHAR(50),
  @EmployeeId INT
AS
BEGIN
  SET NOCOUNT ON;

  SELECT e.EmployeeId, e.BadgeId, e.Name, x.SomeExtraColumn
  FROM Employees e
  LEFT JOIN EmployeeExtras x ON x.EmployeeId = e.EmployeeId
  WHERE e.BadgeId = @BadgeId AND e.EmployeeId = @EmployeeId;
END

Two common ways to handle "active" vs "archived":

  • Keep one table and flip a bit: UPDATE Employees SET Active = 0 WHERE EmployeeId = @EmployeeId — simple, keeps history in-place.
  • Physically move to an archive table inside a transaction so you do not lose data on failures. Example pattern:
CREATE PROCEDURE ArchiveEmployee
  @EmployeeId INT
AS
BEGIN
  SET XACT_ABORT ON;
  BEGIN TRAN;
    INSERT INTO EmployeeArchive (col1, col2, ...)
    SELECT col1, col2, ... FROM Employees WHERE EmployeeId = @EmployeeId;

    DELETE FROM Employees WHERE EmployeeId = @EmployeeId;
  COMMIT TRAN;
END

Call these safely from VB (VB.NET/ADO.NET) using Using blocks, parameter objects (avoid string concatenation), and check affected rows. Add a rowversion/timestamp column for optimistic concurrency, index the badge/employee columns for fast lookup, and log/handle exceptions around your transactions. If a result set can be empty, guard UI bindings against nulls.

Recommended Answers

All 2 Replies

use inner join in SQL.....it is available as a sample example in MSDN or anywhere on the net

similarly, for the next transaction try and insert the relevant record into table2 and then delete it from table1 on some unique key using sql.

Use the same methods as I have described and given examples of in your other threads that already solve this problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.