我有一个代码,其中我使用查询字符串方法将数据插入 SQL 服务器,如下所示,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["x"] != null)
{
if (Request.QueryString["y"] != null)
{
insertData();
}
}
// else
// {
// Response.Redirect("http://localhost:53627/Default.aspx");
// }
}
public void insertData()
{
using (SqlConnection con = new SqlConnection(GetConnectionString()))
{
con.Open();
try
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO Test(x, y) VALUES(@x, @y)", con))
{
cmd.Parameters.Add(new SqlParameter("x", Request.QueryString["x"]));
cmd.Parameters.Add(new SqlParameter("y", Request.QueryString["y"]));
cmd.ExecuteNonQuery();
}
}
catch (Exception Ex)
{
// Console.WriteLine("Unable To Save Data. Error - " + Ex.Message);
Response.Write("Unable To Save Data. Error - " + Ex.Message);
}
}
}
public string GetConnectionString()
{
//sets the connection string from the web config file "ConnString" is the name of the Connection String
return System.Configuration.ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString;
}
}
现在在这个当前代码中,我需要添加系统的日期和时间以及 x 和 y 值......有什么指导吗?