using System; using System.Data; using System.Configuration; 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;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
} protected void btnSubmit_Click(object sender, EventArgs e) { // Guideline for reading the input information after the // uploaded file is selected
string strName = txtName.Text.ToString(); string strAddress = txtAddress.Text.ToString(); string strCity = txtCity.Text.ToString(); string strState = ddlSex.SelectedItem.ToString(); string strMonth = ddlMonth.SelectedItem.ToString(); string strDay = ddlDay.SelectedItem.ToString(); string strYear = ddlYear.SelectedItem.ToString(); string strEye_Color = txtEyeColor.Text.ToString(); string strCoat_Color = txtCoatColor.Text.ToString(); string strFeet = ddlFeet.SelectedItem.ToString(); string strInches = ddlInches.SelectedItem.ToString(); string strWeight = txtWeight.Text.ToString(); string strSex = ddlSex.SelectedItem.ToString(); string strBreed = txtBreed.Text.ToString(); if (FileUpload.PostedFile != null && FileUpload.PostedFile.FileName = !"") { // Getting the uploaded image into bytes and Preparing // for a read byte[] imageSize = new byte [FileUpload.PostedFile.ContentLength]; HttpPostedFile uploadedImage = FileUpload.PostedFile; uploadedImage.InputStream.Read // This is the actual read (imageSize, 0, (int)FileUpload.PostedFile.ContentLength);
// Creating SQL Connection SqlConnection con = new SqlConnection(); con.ConnectionString = ("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Pet_ID.mdf;Integrated Security=True;User Instance=True");
// Creating SQL Commands & Inserting form information //into database table
SqlCommand cmd = new SqlCommand(); cmd.Command.Text = "INSERT INTO Pet_ID (Images Image,Name,Address,City,State,Month,Day,Year,Eye_Color,Coat_Color,Feet,Inches,Weight,Sex,Breed)" + " VALUES (@Image,@Address,@City,@State,@Month,@Day,@Year,@Eye_Color,@Coat_Color,@Feet,@Inches,@Weight,@Sex,@Breed)";
cmd.CommandType = CommandType.Text; cmd.Connection = con; SqlParameter txtName = Command.Parameters.Add("@Name", SqlDbType.Char, 20); txtName.Value = strName.ToString();
SqlParameter txtAddress = Command.Parameters.Add("@Address", SqlDbType.VarChar, 50); txtAddress.Value = strAddress.ToString(); txtCity.Value = strCity.ToString(); cmd.Parameters.Add(txtCity);
ddlState.Value = strState.ToString(); cmd.Parameters.Add(ddlState);
ddlMonth.Value = strMonth.ToString(); cmd.Parameters.Add(ddlMonth);
ddlDay.Value = strDay.ToString(); cmd.Parameters.Add(ddlDay);
ddlYear.Value = strYear.ToString(); cmd.Parameters.Add(ddlYear); txtEyeColor.Value = strEye_Color.ToString(); cmd.Parameters.Add(txtEyeColor); txtCoatColor.Value = strCoat_Color.ToString(); cmd.Parameters.Add(txtEyeColor); ddlFeet.Value = strFeet.ToString(); cmd.Parameters.Add(ddlFeet); ddlInches.Value = strInches.ToString(); cmd.Parameters.Add(ddlInches); txtWeight.Value = strWeight.ToString(); cmd.Parameters.Add(txtWeight); ddlSex.Value = strSex.ToString(); cmd.Parameters.Add(ddlSex); txtBreed.Value = strBreed.ToString(); cmd.Parameters.Add(txtBreed);
// Inserting the picture into the database
SqlParameter FileUpload = new SqlParameter ("@image", SqlDbType.Image, imageSize.Length); //FileUpload.Value = imageSize; cmd.Parameters.Add(Image);
con.Open(); int result = cmd.ExecuteNonQuery(); con.Close(); if (result > 0) lblMessage.Text = "Information Submitted Successfully."; } } }
|