Click here to Skip to main content
15,899,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i am trying to build Employee Attendance system and was successful in assigning TAGS to employees.now i want to calculate in/out timings of employees and which TAG swapped His/Her TAG without displaying any data to end user.


Please Help.

code i am using for saving and assigning Tags to employees is as follows :

What I have tried:

SqlConnection con = new SqlConnection(str);
            con.Open();
            SqlCommand cmd = new SqlCommand("insert into EmpTable(TagID,Firstname,Lastname,Title) values (@TagID,@Firstname,@Lastname,@Title)", con);
          //   cmd.Parameters.AddWithValue("@EmpID", txtempid.Text);
              cmd.Parameters.AddWithValue("@TagID", txttagid.Text);
            cmd.Parameters.AddWithValue("@Firstname", txtfirstname.Text);
            cmd.Parameters.AddWithValue("@Lastname", txtlastname.Text);
            cmd.Parameters.AddWithValue("@Title", txttitle.Text);
            cmd.ExecuteNonQuery();
            MessageBox.Show("Data Saved.");
            con.Close();
Posted
Updated 6-Mar-17 23:56pm
v3
Comments
F-ES Sitecore 7-Mar-17 5:37am    
So your job\coursework is to develop an attendance system and what you have done is create a single table with a single field for the RFID, the only code you have is an insert that doesn't event work, and you want us to do everything else?

You need to change your table such that it a) has a proper name b) has fields you are going to need to do the task in hand. Next google how to do an INSERT using ado.net. After that work out an algorithm that will allow you to work out in\out durations for the employees. No-one here is going to do your homework for you.
F-ES Sitecore 7-Mar-17 5:50am    
Well I had a google and found literally thousands of results so not sure what you were googling for.

https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue(v=vs.110).aspx

It's an update but the concept is the same. What you're missing is that you need to add the parameters to the Parameters collection. The above example shows both ways of doing it, one using the .Add method where you specify the type (and other things like size, direction etc if you need to) and also the AddWithValue which is the simplest and easiest way where ado.net will work out the type etc for you.

1 solution

Add paramter and value to the command
cmd.CommandText = "insert into sample(RFID) values (@RFID)";
          cmd.Parameters.AddWithValue("@RFID", yourRFIDValue); // add this line
 
Share this answer
 
Comments
Nazneen s 7-Mar-17 6:05am    
please check updated question.
Karthik_Mahalingam 7-Mar-17 6:13am    
add this line
cmd.CommandType = CommandType.Text; 
Nazneen s 7-Mar-17 6:17am    
i have two tables. in one table i am assigning tags to the employees ans saving it in EmpTable this part has successfully completed now i need to save whenever user swaps his ID with associated empID.kind of got blank here nor google was able to help so i made this sample table with just one field and trying to save data into this first.in emptable paramater name is tagID.
Karthik_Mahalingam 7-Mar-17 6:19am    
keep a break point and check what value you are passing into the function..
Nazneen s 7-Mar-17 6:23am    
i am swapping the card by connecting RFID reader and can see what value i am inserting into the table but what i want is to save that value and find associated Employee who swapped the card into the database later i will update it wih date time and everything but i got stuck in saving and finding associated employee with the assigned tagID and that was my question in the first place but seems i just went stupid and posted something else.

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