using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.IO; using System.Configuration; public partial class _Default : System.Web.UI.Page { SqlConnection SqlCoon = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["RSIC"].ConnectionString); protected void Page_Load(object sender, EventArgs e) { if (Session["username"] == null) { Response.Redirect("login.aspx"); } } protected void btnSubmit_Click(object sender, EventArgs e) { try { if (SqlCoon.State != ConnectionState.Open) { SqlCoon.Open(); } string str1 = txtNewsDate.Text; string[] dtSplit = str1.Split('-'); string storedate = dtSplit[1] + "-" + dtSplit[0] + "-" + dtSplit[2]; string ins = "Insert into news(Title,pDate,mnt,detail) values('" + txtNewsTitle.Text + "','" + storedate + "','" + dtSplit[1] + "','" + txtNewsDetails.Text + "')"; SqlCommand cmd = new SqlCommand(ins, SqlCoon); int j = cmd.ExecuteNonQuery(); if (j != 0) { Label1.Visible = true; Label1.Text = "News Add Successfully "; EmptyTextField(); } else { EmptyTextField(); Label1.Visible = true; Label1.Text = "Please Contact To Adminm Or try Again"; } } catch (Exception ex) { EmptyTextField(); Label1.Visible = true; Label1.Text = "Please Contact To Adminm :" + ex.Message.ToString(); } finally { SqlCoon.Close(); } } void EmptyTextField() { txtNewsTitle.Text = string.Empty; txtNewsDate.Text = string.Empty; txtNewsDetails.Text = string.Empty; } }