While click the link button will automatically insert the current date in my table how to do that?
Thanks&Regs
Magesh.A
While click the link button will automatically insert the current date.
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
SenthilkumarRank #387 · 6.5K pointsPosted Mar 29, 2012, 12:35 AM EDT
Create the table.
Design page:
Code File:
using System; using System.Collections; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class ViewInsert : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void lbtnInsert_Click(object sender, EventArgs e) { try { SqlConnection sqlConnection = new SqlConnection(); sqlConnection.ConnectionString = @"Data Source=SS438\SQLEXPRESS;Initial Catalog=Examples;Integrated Security=true;"; sqlConnection.Open(); string sqlQuery = "INSERT INTO Views(UserID) VALUES (@UserID)"; SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection); sqlCommand.CommandType = CommandType.Text; Random random = new Random(1); sqlCommand.Parameters.Add("UserID", SqlDbType.VarChar).Value = random.Next(10000); sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); lblMessage.Text = "Inserted successfully..."; } catch (Exception ex) { Response.Write(ex.Message); } } }Hope this will help you...