using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.SqlClient; using sss;
public partial class doucupload : System.Web.UI.Page { string getconnection = ConfigurationManager.AppSettings["get"]; Class1 ob = new Class1(); SqlConnection con; SqlDataReader dr; SqlCommand cmd; SqlDataAdapter da; DataSet ds=new DataSet (); protected void Page_Load(object sender, EventArgs e) { if (IsPostBack!=true) { filldata(); }
}
protected void Button1_Click(object sender, EventArgs e) { if (hid.Value == "") { string url = Server.MapPath(".."); Random RandomClass = new Random(); int RandomNumber = RandomClass.Next(10, 99); string filename = RandomNumber.ToString() + upfile.FileName; upfile.PostedFile.SaveAs(url + "/upload/" + filename);
con = new SqlConnection(getconnection); con.Open(); SqlParameter[] sp = new SqlParameter[3];
sp[0] = new SqlParameter("@title", SqlDbType.NVarChar, 50); sp[0].Value = TextBox1.Text;
sp[1] = new SqlParameter("@filename", SqlDbType.NVarChar, 50); sp[1].Value = filename;
sp[2] = new SqlParameter("@status", SqlDbType.Char, 10); sp[2].Value = DropDownList1.SelectedValue;
cmd = new SqlCommand("fileup", con); cmd.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter sqlparams in sp) { cmd.Parameters.Add(sqlparams); } cmd.ExecuteNonQuery(); con.Close(); } else { con = new SqlConnection(getconnection); if (upfile.FileName == "") { cmd = new SqlCommand("update fileupload set title='" + TextBox1.Text + "',status='"+DropDownList1 .SelectedValue +"' where fileid='" + hid.Value + "'", con); } else { string url = Server.MapPath(".."); Random RandomClass = new Random(); int RandomNumber = RandomClass.Next(10, 99); string filename = RandomNumber.ToString() + upfile.FileName; upfile.PostedFile.SaveAs(url + "/upload/" + filename); cmd = new SqlCommand("update fileupload set title='" + TextBox1.Text + "',filename='" + filename + "',status='" + DropDownList1.SelectedValue + "' where fileid='" + hid.Value + "'", con); } con.Open(); cmd.ExecuteNonQuery(); con.Close(); }
hid.Value = ""; filldata(); } public void filldata() { con = new SqlConnection(getconnection); da = new SqlDataAdapter ("select * from fileupload", con); da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); } protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "ed") { con = new SqlConnection(getconnection); cmd = new SqlCommand("select * from fileupload where fileid='"+e.CommandArgument +"'", con); hid.Value = e.CommandArgument.ToString (); con.Open(); dr = cmd.ExecuteReader(); if (dr.Read()) { TextBox1.Text = dr["title"].ToString(); DropDownList1.SelectedValue = dr["status"].ToString();
} con.Close(); } if (e.CommandName == "del") { con = new SqlConnection(getconnection); cmd = new SqlCommand("delete from fileupload where fileid='" + e.CommandArgument + "'", con); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } filldata(); } }
|
| Author: Neeraj Saluja 12 May 2008 | Member Level: Gold Points : 2 |
Providing some explanation and highlighting the key syntaxes will help the readers. Even if you can add code comments using "//", that would also add value to it.
|