2 Replies - 1172 Views - Last Post: 15 March 2011 - 04:23 AM Rate Topic: -----

#1 Atomika3000  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 15-October 10

Inserting Images Into An SQL Database

Posted 15 March 2011 - 03:45 AM

I am having an issue, i currently have a C# application that inserts records into an SQL database, i can get it to insert everything except images.

my current INSERT query is:

 string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename='K:\Uni (Year 3)\EJ315028S - Software Apps Framework\Projects\CoffeeInfo.mdf';Integrated Security=True;Connect Timeout=30;User Instance=True";

            int coffeeID = 0;

            using (SqlConnection cn = new SqlConnection(connectionString))
            using (SqlCommand cmd = cn.CreateCommand())
            {
                cmd.CommandText = "SELECT MAX(CoffeeID) FROM Coffee";
                cmd.CommandType = CommandType.Text;

                cn.Open();

                coffeeID = (int)cmd.ExecuteScalar();

                int newCoffeeID = coffeeID + 1;

                cmd.CommandText = "INSERT INTO Coffee (CoffeeID, CoffeeName, CoffeeStrength, CoffeeOrigin, CoffeePrice, CoffeeStock, CoffeeImage) VALUES (@CoffeeID, @Name, @Strength, @Origin, @Price, @Quantity)";

                cmd.Parameters.AddWithValue("@CoffeeID", newCoffeeID);
                cmd.Parameters.AddWithValue("@Name", txtName.Text);
                cmd.Parameters.AddWithValue("@Strength", txtStrength.Text);
                cmd.Parameters.AddWithValue("@Origin", txtOrigin.Text);
                cmd.Parameters.AddWithValue("@Price", txtPrice.Text);
                cmd.Parameters.AddWithValue("@Quantity", txtStock.Text);
                //cmd.Parameters.AddWithValue("@Image", null);

                cmd.ExecuteNonQuery();
            }


How can i go about changing this to insert images into my database, also, how would i go about adding images into my insert query? is there a specific tool built into Visual Studio 2008 to do so?

Is This A Good Question/Topic? 0
  • +

Replies To: Inserting Images Into An SQL Database

#2 BigR1983  Icon User is offline

  • D.I.C Head

Reputation: 57
  • View blog
  • Posts: 221
  • Joined: 12-April 10

Re: Inserting Images Into An SQL Database

Posted 15 March 2011 - 03:55 AM

http://www.dreaminco...-a-sql-databse/

perhaps the answer you seek is here
Was This Post Helpful? 2
  • +
  • -

#3 Atomika3000  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 15-October 10

Re: Inserting Images Into An SQL Database

Posted 15 March 2011 - 04:23 AM

It did thanks, forgot to search!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1