Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi frnds,

am working on Asp.net,C#,SqlServer 2005.

On webpage I have Gridview to enter the records from Footer Textboxes.

I want to Save record added Date and Time in Database when Footer add button click.
and also I want to Save Username who added the record.

We have login page for this proj.....so I must save Username also when adding record.

In database I have Two fields

1)Record_EnteredDate
2)Record_EnteredBy.

and This is my code for adding New Record from Row Command

protected void GVRecordsEntry_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        

        if (e.CommandName.Equals("AddNew"))
        {
           
            TextBox TxtStudentName = (TextBox)GVRecordsEntry.FooterRow.FindControl("txtftrStudentName");
            TextBox TxtRollNo = (TextBox)GVRecordsEntry.FooterRow.FindControl("txtftrRollNo");
            TextBox TxtFatherName = (TextBox)GVRecordsEntry.FooterRow.FindControl("txtftrFatherName");
            TextBox TxtLocation = (TextBox)GVRecordsEntry.FooterRow.FindControl("txtftrLocation");

	// Add Record Entry Date time
	// Add Record Entered UserName
            
          
            con.Open();

                SqlCommand cmd = new SqlCommand("INSERT into StudentRecs (StudentName,RollNo,FatherName,Location) VALUES ('" + TxtStudentName .Text + "','" + TxtRollNo.Text + "','" + TxtFatherName.Text + "','" + TxtLocation.Text + "')", con);
                int result = cmd.ExecuteNonQuery();
                con.Close();



                if (result == 1)
                {
                    LoadInventoryData();
                   
                }
      

        }
    }



Just I want to add Record Entered Date and Time....
and Recored entered by UserName.

Please help me.

Thanks in Advance.
Posted
Updated 6-Jul-13 22:01pm
v2

1 solution

Add two columns to your table StudentRecs (UserID,EntryDate)
Store the UserID in session at login time Session["UserID"]=UserID
then modify you query like this
C#
SqlCommand cmd = new SqlCommand("INSERT into StudentRecs (StudentName,RollNo,FatherName,Location,UserID,EntryDate) VALUES ('" + TxtStudentName .Text + "','" + TxtRollNo.Text + "','" + TxtFatherName.Text + "','" + TxtLocation.Text + "','"+Session[UserID].ToString()+"',getdate())", con);


hope this will fix your problem
 
Share this answer
 
v2
Comments
Member239258 7-Jul-13 6:25am    
sorry, am unable to see Datetime and UserName in Database Table.

No Errors.

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