C:\Users\shiva\OneDrive\Documents\Visual Studio 2008\WebSites\shiva\Default.aspx.
cs 1
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net;
using System.IO;
using System.Web.ApplicationServices;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-SHIVA\SQLEXPRESS; Initial
Catalog=shivam1;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
string str;
int ans;
//string ImageLabel;
ReportDocument rdoc = new ReportDocument();
SqlDataAdapter sda = new SqlDataAdapter();
protected void Page_Load(object sender, EventArgs e)
{
void clear()
{
TextBoxYear.Text = "";
TextBoxContact.Text = "";
TextBoxLname.Text = "";
TextBoxName.Text = "";
TextBoxRoll.Text = "";
DropDownListBranch.SelectedIndex = 0;
}
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
byte[] mydata;
string imagePath = Server.MapPath("Images/" + Label4.Text);
FileInfo finfo = new FileInfo(imagePath);
long numbyte = finfo.Length;
FileStream fstream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
BinaryReader breader = new BinaryReader(fstream);
mydata = breader.ReadBytes(Convert.ToInt32(numbyte));
str="insert into shivamg(fname,lname,rollno,branch,year,contact,img) values('" +
TextBoxName.Text+"','"+TextBoxLname.Text+"','" + TextBoxRoll.Text+"','"+
DropDownListBranch.Text+"','"+TextBoxYear.Text+"','" + TextBoxContact.Text+"',@img)";
con.Open();
cmd.Connection=con;
cmd.CommandText=str;
cmd.Parameters.Add(new SqlParameter("@img", (object)mydata));
cmd.ExecuteNonQuery();
con.Close();
Label3.Visible = true;
con.Open();
string id = "YOUR ID IS :- ";
str = "Select max(userId) from shivamg";
C:\Users\shiva\OneDrive\Documents\Visual Studio 2008\WebSites\shiva\Default.aspx.cs 2
cmd.Connection = con;
cmd.CommandText = str;
ans = (int)cmd.ExecuteScalar();
Label2.Text = ans.ToString();
userId.Text = id + ans;
con.Close();
clear();
}
protected void ButtonReport_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
DataSet1 ds1 = new DataSet1();
rdoc.Load(Server.MapPath("CrystalReport.rpt"));
str = "Select * from shivamg where userId=" + Label2.Text;
con.Open();
cmd.Connection = con;
cmd.CommandText = str;
sda.SelectCommand = cmd;
sda.Fill(ds1, "DataTable1");
rdoc.SetDataSource(ds1);
CrystalReportViewer1.ReportSource = rdoc;
con.Close();
rdoc.PrintToPrinter(1, false, 1, 1);
Label3.Text = "REPORT IS GENERATED SUCCESSFULLY !";
}
protected void ButtonUpload_Click(object sender, EventArgs e)
{
Label4.Text = FileUpload1.FileName;
FileUpload1.SaveAs(Server.MapPath("Images/" + FileUpload1.FileName));
Image1.Attributes.Add("src", "Images/" + FileUpload1.FileName);
}
}