SQL upload images problem

hello glad to be here,
i have a upload images tutoiral that i got from here
http://geekswithblogs.net/dotNETvinz...n-asp.net.aspx
but i can not get it to work, it is slightly tweaked for me.
errors i am getting are:
------ Build started: Project: C:WebSite4, Configuration: Debug Any CPU ------
Validating Web Site
Building directory '/WebSite4/'.
C:WebSite4Default.aspx.cs(35,9): error CS0246: The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?)
C:WebSite4Default.aspx.cs(35,34): error CS0246: The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?)
C:WebSite4Default.aspx.cs(42,13): error CS0246: The type or namespace name 'SqlCommand' could not be found (are you missing a using directive or an assembly reference?)
C:WebSite4Default.aspx.cs(42,34): error CS0246: The type or namespace name 'SqlCommand' could not be found (are you missing a using directive or an assembly reference?)
C:WebSite4Default.aspx.cs(43,13): error CS0246: The type or namespace name 'SqlParameter' could not be found (are you missing a using directive or an assembly reference?)
C:WebSite4Default.aspx.cs(43,40): error CS0246: The type or namespace name 'SqlParameter' could not be found (are you missing a using directive or an assembly reference?)
C:WebSite4Default.aspx.cs(46,28): error CS0246: The type or namespace name 'SqlParameter' could not be found (are you missing a using directive or an assembly reference?)
C:WebSite4Default.aspx.cs(46,49): error CS0103: The name 'SqlDbType' does not exist in the current context
C:WebSite4Default.aspx.cs(47,28): error CS0246: The type or namespace name 'SqlParameter' could not be found (are you missing a using directive or an assembly reference?)
C:WebSite4Default.aspx.cs(47,50): error CS0103: The name 'SqlDbType' does not exist in the current context
C:WebSite4Default.aspx.cs(48,28): error CS0246: The type or namespace name 'SqlParameter' could not be found (are you missing a using directive or an assembly reference?)
C:WebSite4Default.aspx.cs(48,53): error CS0103: The name 'SqlDbType' does not exist in the current context
C:WebSite4Default.aspx.cs(49,28): error CS0246: The type or namespace name 'SqlParameter' could not be found (are you missing a using directive or an assembly reference?)
C:WebSite4Default.aspx.cs(49,53): error CS0103: The name 'SqlDbType' does not exist in the current context
C:WebSite4Default.aspx.cs(61,31): error CS0103: The name 'CommandType' does not exist in the current context
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
<b>Default.aspx</b>
<code>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Browse Image:<br />
<br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Save" Width="79px" />
</div>
</form>
</body>
</html>
</code>
<b>Default.aspx.cs</b>
<code>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
private void StartUpLoad()
{
//get the image file that was posted (binary format)
byte[] theImage = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload1.PostedFile;
Image.InputStream.Read(theImage, 0, (int)FileUpload1.PostedFile.ContentLength);
int length = theImage.Length; //get the length of the image
string fileName = FileUpload1.FileName.ToString(); //get the file name of the posted image
string type = FileUpload1.PostedFile.ContentType; //get the type of the posted image
int size = FileUpload1.PostedFile.ContentLength; //get the size in bytes that
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{
//Call the method to execute Insertion of data to the Database
ExecuteInsert(theImage, type, size, fileName, length);
Response.Write("Save Successfully!");
}
}
public string GetConnectionString()
{
//sets the connection string from your web config file "ConnString" is the name of your Connection String
return System.Configuration.ConfigurationManager.ConnectionStrings["MyConsString">.ConnectionString;
}
private void ExecuteInsert(byte[] Image, string Type, Int64 Size, string Name, int length)
{
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO TblImages (Image, ImageType, ImageSize, ImageName) VALUES "
+ " (@img,@type,@imgsize,@imgname)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[4];
//param[0] = new SqlParameter("@id", SqlDbType.Int, 20);
param[0] = new SqlParameter("@img", SqlDbType.Image, length);
param[1] = new SqlParameter("@type", SqlDbType.NVarChar, 50);
param[2] = new SqlParameter("@imgsize", SqlDbType.BigInt, 9999);
param[3] = new SqlParameter("@imgname", SqlDbType.NVarChar, 50);
param[0].Value = Image;
param[1].Value = Type;
param[2].Value = Size;
param[3].Value = Name;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
StartUpLoad();
}
}
</code>
<b>web.config</b>
<code>
<connectionStrings>
<add name="MyConsString" connectionString="ZONE777SQLS;Initial" Catalog="newDB;Integrated" Security="True;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</code>
i have tried a whoel bunch of these tutorials and i have not got only one to work but then
the display did not work.
if any one know of a tutorial that show how to store just the path of the image and then
store and display them with asp.net, I would greatly appreciate it.
thanks,
craig

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

Processing your response...

Discuss This Question: 7 &nbspReplies

There was an error processing your information. Please try again later.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

thank you so much. i am learning, i imagine that needs to be called for
these to work:
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[4];
I am not sure what he or she is doing here:
catch (System.Data.SqlClient.SqlException ex)
well these are the errors i am getting now.
------ Build started: Project: C:WebSite4, Configuration: Debug Any CPU ------
Validating Web Site
Building directory '/WebSite4/'.
C:WebSite4Default.aspx.cs(47,49): error CS0103: The name 'SqlDbType' does not exist in the current context
C:WebSite4Default.aspx.cs(48,50): error CS0103: The name 'SqlDbType' does not exist in the current context
C:WebSite4Default.aspx.cs(49,53): error CS0103: The name 'SqlDbType' does not exist in the current context
C:WebSite4Default.aspx.cs(50,53): error CS0103: The name 'SqlDbType' does not exist in the current context
C:WebSite4Default.aspx.cs(62,31): error CS0103: The name 'CommandType' does not exist in the current context
Validation Complete
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
thanks,
craig

thanks carlos that worked by adding those 2.
but this is not loading into the database. i checked by going to the table and
asked it to show the table data. it also is not responding " Save Successfully! "
i do not why it is not working, do know of any other examples that may work?
thanks
craig

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy

Processing your reply...

Ask a Question

Free Guide: Managing storage for virtual environments

Complete a brief survey to get a complimentary 70-page whitepaper featuring the best methods and solutions for your virtual environment, as well as hypervisor-specific management advice from TechTarget experts. Don’t miss out on this exclusive content!

To follow this tag...

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States.
Privacy