Jay

Jay

  • NA
  • 1
  • 0

C# Database value, assembly and other errors. Please Help.

Sep 30 2009 12:24 PM
Hey guys, I'm working on an upload page that uploads the information from a form and upload box from an ASP page to a database. When I finished, I got alot of errors but I cleared up most of them now I have a few more error. and help would be appreciated.

here is my C# code:


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.";
        }
    }
   
}

 
Here is my ASP code:

 <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h4>I. Please select picture for upload.</h4>
<br />
<asp:FileUpload ID="FileUpload" runat="server"></asp:FileUpload>
<br />
<br />
<h4>II. Please fill in pet information.</h4>
<br />
<asp:Label ID="lblName" runat="server">Name :</asp:Label>
<asp:TextBox ID="txtName" runat="server" Width="95px"></asp:TextBox>
<br />
<asp:Label ID="lblAddress" runat="server">Address :</asp:Label>
<asp:TextBox ID="txtAddress" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblCity" runat="server">City :</asp:Label>
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
<asp:Label ID="lblState" runat="server">State :</asp:Label>
<asp:DropDownList ID="ddlState" runat="server">
<asp:ListItem>AL</asp:ListItem>
<asp:ListItem>AK</asp:ListItem>
<asp:ListItem>AR</asp:ListItem>
<asp:ListItem>AS</asp:ListItem>
<asp:ListItem>AZ</asp:ListItem>
<asp:ListItem>CA</asp:ListItem>
<asp:ListItem>CO</asp:ListItem>
<asp:ListItem>CT</asp:ListItem>
<asp:ListItem>DC</asp:ListItem>
<asp:ListItem>DE</asp:ListItem>
<asp:ListItem>FL</asp:ListItem>
<asp:ListItem>FM</asp:ListItem>
<asp:ListItem>GA</asp:ListItem>
<asp:ListItem>GU</asp:ListItem>
<asp:ListItem>HI</asp:ListItem>
<asp:ListItem>IA</asp:ListItem>
<asp:ListItem>ID</asp:ListItem>
<asp:ListItem>IL</asp:ListItem>
<asp:ListItem>IN</asp:ListItem>
<asp:ListItem>KS</asp:ListItem>
<asp:ListItem>KY</asp:ListItem>
<asp:ListItem>LA</asp:ListItem>
<asp:ListItem>MA</asp:ListItem>
<asp:ListItem>MD</asp:ListItem>
<asp:ListItem>ME</asp:ListItem>
<asp:ListItem>MH</asp:ListItem>
<asp:ListItem>MI</asp:ListItem>
<asp:ListItem>MN</asp:ListItem>
<asp:ListItem>MO</asp:ListItem>
<asp:ListItem>MS</asp:ListItem>
<asp:ListItem>MT</asp:ListItem>
<asp:ListItem>NC</asp:ListItem>
<asp:ListItem>ND</asp:ListItem>
<asp:ListItem>NE</asp:ListItem>
<asp:ListItem>NH</asp:ListItem>
<asp:ListItem>NJ</asp:ListItem>
<asp:ListItem>NM</asp:ListItem>
<asp:ListItem>NV</asp:ListItem>
<asp:ListItem>NY</asp:ListItem>
<asp:ListItem>OH</asp:ListItem>
<asp:ListItem>OK</asp:ListItem>
<asp:ListItem>OR</asp:ListItem>
<asp:ListItem>PA</asp:ListItem>
<asp:ListItem>PR</asp:ListItem>
<asp:ListItem>PW</asp:ListItem>
<asp:ListItem>RI</asp:ListItem>
<asp:ListItem>SC</asp:ListItem>
<asp:ListItem>SD</asp:ListItem>
<asp:ListItem>TN</asp:ListItem>
<asp:ListItem>TX</asp:ListItem>
<asp:ListItem>UT</asp:ListItem>
<asp:ListItem>VA</asp:ListItem>
<asp:ListItem>VI</asp:ListItem>
<asp:ListItem>VT</asp:ListItem>
<asp:ListItem>WA</asp:ListItem>
<asp:ListItem>WI</asp:ListItem>
<asp:ListItem>WV</asp:ListItem>
<asp:ListItem>WY</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="lblBirthdate" runat="server">Birthdate :</asp:Label>
<asp:DropDownList ID="ddlMonth" runat="server">
<asp:ListItem>Jan</asp:ListItem>
<asp:ListItem>Feb</asp:ListItem>
<asp:ListItem>Mar</asp:ListItem>
<asp:ListItem>Apr</asp:ListItem>
<asp:ListItem>May</asp:ListItem>
<asp:ListItem>Jun</asp:ListItem>
<asp:ListItem>Jul</asp:ListItem>
<asp:ListItem>Aug</asp:ListItem>
<asp:ListItem>Sep</asp:ListItem>
<asp:ListItem>Oct</asp:ListItem>
<asp:ListItem>Nov</asp:ListItem>
<asp:ListItem>Dec</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlDay" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
<asp:ListItem>13</asp:ListItem>
<asp:ListItem>14</asp:ListItem>
<asp:ListItem>15</asp:ListItem>
<asp:ListItem>16</asp:ListItem>
<asp:ListItem>17</asp:ListItem>
<asp:ListItem>18</asp:ListItem>
<asp:ListItem>19</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>21</asp:ListItem>
<asp:ListItem>22</asp:ListItem>
<asp:ListItem>23</asp:ListItem>
<asp:ListItem>24</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>26</asp:ListItem>
<asp:ListItem>27</asp:ListItem>
<asp:ListItem>28</asp:ListItem>
<asp:ListItem>29</asp:ListItem>
<asp:ListItem>30</asp:ListItem>
<asp:ListItem>31</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlYear" runat="server">
<asp:ListItem>1980</asp:ListItem>
<asp:ListItem>1981</asp:ListItem>
<asp:ListItem>1982</asp:ListItem>
<asp:ListItem>1983</asp:ListItem>
<asp:ListItem>1984</asp:ListItem>
<asp:ListItem>1985</asp:ListItem>
<asp:ListItem>1986</asp:ListItem>
<asp:ListItem>1987</asp:ListItem>
<asp:ListItem>1988</asp:ListItem>
<asp:ListItem>1989</asp:ListItem>
<asp:ListItem>1990</asp:ListItem>
<asp:ListItem>1991</asp:ListItem>
<asp:ListItem>1992</asp:ListItem>
<asp:ListItem>1993</asp:ListItem>
<asp:ListItem>1994</asp:ListItem>
<asp:ListItem>1995</asp:ListItem>
<asp:ListItem>1996</asp:ListItem>
<asp:ListItem>1997</asp:ListItem>
<asp:ListItem>1998</asp:ListItem>
<asp:ListItem>1999</asp:ListItem>
<asp:ListItem>2000</asp:ListItem>
<asp:ListItem>2001</asp:ListItem>
<asp:ListItem>2002</asp:ListItem>
<asp:ListItem>2003</asp:ListItem>
<asp:ListItem>2004</asp:ListItem>
<asp:ListItem>2005</asp:ListItem>
<asp:ListItem>2006</asp:ListItem>
<asp:ListItem>2007</asp:ListItem>
<asp:ListItem>2008</asp:ListItem>
<asp:ListItem>2009</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="lblCoatColor" runat="server">Coat Color :</asp:Label>
<asp:TextBox ID="txtCoatColor" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblEyeColor" runat="server">Eye Color :</asp:Label>
<asp:TextBox ID="txtEyeColor" runat="server"></asp:TextBox>
<br />
<asp:Label ID="Height" runat="server">Height :</asp:Label>
<asp:DropDownList ID="ddlFeet" runat="server">
<asp:ListItem>1'</asp:ListItem>
<asp:ListItem>2'</asp:ListItem>
<asp:ListItem>3'</asp:ListItem>
<asp:ListItem>4'</asp:ListItem>
<asp:ListItem>5'</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ddlInches" runat="server">
<asp:ListItem>0"</asp:ListItem>
<asp:ListItem>1"</asp:ListItem>
<asp:ListItem>2"</asp:ListItem>
<asp:ListItem>3"</asp:ListItem>
<asp:ListItem>4"</asp:ListItem>
<asp:ListItem>5"</asp:ListItem>
<asp:ListItem>6"</asp:ListItem>
<asp:ListItem>7"</asp:ListItem>
<asp:ListItem>8"</asp:ListItem>
<asp:ListItem>9"</asp:ListItem>
<asp:ListItem>10"</asp:ListItem>
<asp:ListItem>11"</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="lblWeight" runat="server">Weight :</asp:Label>
<asp:TextBox ID="txtWeight" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblSex" runat="server">Sex :</asp:Label>
<asp:DropDownList ID="ddlSex" runat="server">
<asp:ListItem>M</asp:ListItem>
<asp:ListItem>F</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Label ID="lblBreed" runat="server">Breed :</asp:Label>
<asp:TextBox ID="txtBreed" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnSubmit" runat="server" text="Submit" OnClick="btnSubmit_Click" />
<br />
<br />
<asp:Label ID="lblMessage" runat="server"></asp:Label><br />
</div>
</form>
</body>
</html>



Answers (1)