I have a Log table in SQL.
Table
ID UserName VisitedTime VisitedUrl IpAdress Browser
I can save UserName,VisitedTime,VisitedUrl,IpAdress,Browser when current user visit any page.
Controller
public ActionResult Index(string date1, string date2, string txt)
{
string browser = Request.Browser.Browser;
string IP = HttpContext.Request.UserHostAddress;
string userName = HttpContext.User.Identity.Name.ToString();
string url = Request.Url.AbsoluteUri.ToString();
mydataclass newDataclass=new mydataclass ();
string sql = @"Insert Into Loglar (UserName,VisitedTime,VisitedUrl,IpAdress,Browser ) values
('" + userName.ToString() + "','" + DateTime.Now.ToString() + "','"
+ url+ "','" + IP+ "','" + browser+ "')";
newDataclass.DataCenterDoSql(sql);
}
Class
public class mydataclass
{
public mydataclass () { }
public bool DataCenterDoSql(string sql)
{
SqlConnection con = new SqlConnection();
try
{
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
con.Open();
}
catch
{
}
SqlCommand cmd = new SqlCommand();
try
{
cmd.Connection = con;
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
return true;
}
catch (Exception e)
{
return false;
}
finally
{
con.Close();
}
return true;
}
}
It is working.There is no any problem.
I have two DateEdit,one button,one textbox and a grid on ViewPartial. When I select two date,enter string to textbox and click button results of some things can display on gridview.
My question : How can I save DateEdit 1, DateEdit 2 and TextBox value to my new table after click button.
New Table
ID UserName VisitedTime VisitedUrl IpAdress Browser Date1 Date2 TextBox