Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been trying to resolve this for quite some time now but not achieved yet. My problem is i am trying to insert values of my fields(firstname,rfid,sdt(datetime)) into datatab and display a report of that data.

now the scenario is rfid card can be swiped a number of times throughout the day by the employee i am storing that data into my admin table and i have successfully accomplished displaying and storing rfid and sdt fields into the table but firstname must be fetched from table Admin in which unique tag of rfid at the time of registration of employee is assigned to them.

I have tried joins,multiple queries into one but nothing worked for me so far. query to store those two values is :

What I have tried:

C#
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand cmd = new SqlCommand("Insert into Datatab(firstname) Select Distinct firstname from Admin", con);
cmd.Parameters.AddWithValue("@firstname", txtname.Text);
//       cmd.Parameters.AddWithValue("@rfid", txtname.Text);
cmd.ExecuteNonQuery();
con.Close();

I want the name of the specific employee who swipes his/her card for n no of times with rfid of that employee to be saved into the database.
Posted
Updated 20-Mar-17 3:26am
v2
Comments
CHill60 20-Mar-17 9:10am    
I think you are going to need a WHERE clause in there somewhere
Nazneen s 21-Mar-17 3:57am    
i tried that and it works if there is one condition but where clause is not working as i am not fetching data for one employee .

1 solution

Don't.
The "proper" way to do this is to keep the user data in your Admin table, as you are with the Rfid tag code that is assigned. Then when you get a tag swipe, you store the tag code in Datatab (and probably a timestamp as well) but no other information.
When you want to retrieve the user data and timestamp you use a JOIN to correlate the rfid tag from the Datatab to the username from the Admin table.

If you don't do it this way, you are duplicating information, wasting DB space, and potentially causing yourself problems later. Consider this: what if the user changes their name? In a properly designed system, the change has to be recorded in one location. In yours, there are potentially thousands that need updating.
 
Share this answer
 
Comments
Nazneen s 21-Mar-17 4:02am    
i am doing it same way you explained @originalgriff and timestamp and tag is getting fetched successfully but name is not getting displayed.so what i need is to get name tag and timestamp to b displayed in the report and for that i need the query i tried using join but then all the name are getting displayed otherwise just name getting displayed from my above query. thats why i need help.
OriginalGriff 21-Mar-17 4:12am    
Show the JOIN query you used.
Nazneen s 21-Mar-17 4:20am    
SELECT Admin.firstname from Admin inner join Datatab on Admin.firstname = Datatab.firstname

Insert into Datatab(rfid,firstname) Select (rfid,firstname) from Admin INNER JOIN Datatab ON Admin.firstname=Datatab.firstname

And many more like this but nothing worked so far.
OriginalGriff 21-Mar-17 4:54am    
You didn't listen to anything I said, did you?
Look at what I said, then look at your query. What are you storing in the tables? Why?
Nazneen s 21-Mar-17 5:04am    
i have two tables Admin and Datatab.in admin i am storing all the details about the employee and rfid is primary key there in second table Datatab i am storing timings,name and rfid card tag of that employee to identify number of times employee has been in and out from the Company.

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