Click here to Skip to main content
11,412,182 members (62,083 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.5
After inserting the data...image and description not insert that particular row as am using session for that...and the error is ("Missing semicolon (;) at end of SQL statement.") and the when i next time run the program i can see the image in the datalist bt
not in database....plz tell me...see the code below...

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //Get Filename from fileupload control
        String extention;
        String name = fileuploadimages.FileName;
        String name1 = name.ToUpper();
 
        if (name1.EndsWith(".JPG"))
            extention = ".JPG";
        else if (name1.EndsWith(".GIF"))
            extention = ".GIF";
        else if (name1.EndsWith(".JPEG"))
            extention = ".JPEG";
        else
            extention = "";
 

        String filename = Path.GetFileName(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Today.Minute.ToString() + DateTime.Now.Second.ToString() + extention);
        //Save images into SlideImages folder

        fileuploadimages.SaveAs(Server.MapPath("SlideImages/" + filename));
        //Open the database connection
        con.Open();
        //Query to insert images name and Description into database
        OleDbCommand cmd = new OleDbCommand("Insert into SlideShowTable(ImageName,Description) values(@ImageName,@Description) where CategoryID='" + txtcat.Text + "'And ArName='" + txtarea.Text + "' ", con);
        //Passing parameters to query
        cmd.Parameters.AddWithValue("@ImageName", filename);
        cmd.Parameters.AddWithValue("@Description", txtDesc.Text);
        cmd.ExecuteNonQuery();
        //Close dbconnection

        txtDesc.Text = string.Empty;
        //BindDataList();

 
        // string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
        string targetPath = Server.MapPath("SlideImages/" + filename);
        Stream strm = fileuploadimages.PostedFile.InputStream;
        var targetFile = targetPath;
        //Based on scalefactor image size will vary
        GenerateThumbnails(0.5, strm, targetFile);
        con.Close();
        BindDataList();
    }
 
    private void GenerateThumbnails(double scaleFactor, Stream sourcePath, string targetPath)
    {
        using (var image = Image.FromStream(sourcePath))
        {
            var newWidth = (int)(700 * scaleFactor);
            var newHeight = (int)(700 * scaleFactor);
            var thumbnailImg = new Bitmap(newWidth, newHeight);
            var thumbGraph = Graphics.FromImage(thumbnailImg);
            thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
            thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
            thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
            var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
            thumbGraph.DrawImage(image, imageRectangle);
            thumbnailImg.Save(targetPath, image.RawFormat);
        }
    }
}
Posted 11-Mar-13 21:47pm
Raj@88375
Edited 11-Mar-13 21:52pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

wrong query....

Insert into ... with where condition is wrong
OleDbCommand cmd = new OleDbCommand("Insert into SlideShowTable(ImageName,Description) values(@ImageName,@Description) where CategoryID='" + txtcat.Text + "'And ArName='" + txtarea.Text + "' ", con);

syntax is
Insert into tblnm(column list...) values(value list...)

Happy Coding!
Smile | :)
  Permalink  
Comments
ashishadi at 12-Mar-13 5:12am
   
what is the mistake...didn't getting..plz tell me..
Aarti Meswania at 12-Mar-13 5:13am
   
it should be

OleDbCommand cmd = new OleDbCommand("Insert into SlideShowTable(ImageName,Description) values(@ImageName,@Description)", con);
ashishadi at 12-Mar-13 5:25am
   
sir...i know that bt...i want insert the data in particular row..where the data is already filled bt not these 2 colm ...for this i hv taken these value in session from another page...

wait...
the another page coding is given below..

using System;
using System.Collections;
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.OleDb;
using System.IO;

public partial class CreatAdverties : System.Web.UI.Page
{
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());


protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bindcatogeryropdown();
BindAreadropdown();
}

}

protected void BindAreadropdown()
{
//conenction path for database

con.Open();
OleDbCommand cmd = new OleDbCommand("select * from AreaTable", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlCreateAddArea.DataSource = ds;
ddlCreateAddArea.DataTextField = "AreaName";
ddlCreateAddArea.DataValueField = "AreaID";
ddlCreateAddArea.DataBind();
ddlCreateAddArea.Items.Insert(0, new ListItem("Select Area", "0"));
ddlCreateAddArea.Items.Insert(0, new ListItem("Select Category ", "0"));

}

protected void Bindcatogeryropdown()
{
//conenction path for database

con.Open();
OleDbCommand cmd = new OleDbCommand("select * from catname", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddlCreateAddCategory.DataSource = ds;
ddlCreateAddCategory.DataTextField = "CategoryName";
ddlCreateAddCategory.DataValueField = "ID";
ddlCreateAddCategory.DataBind();
ddlCreateAddArea.Items.Insert(0, new ListItem("Select Area", "0"));
ddlCreateAddCategory.Items.Insert(0, new ListItem("Select Category ", "0"));

}

public void ddlCreateAddArea_SelectedIndexChanged(object sender, EventArgs e)
{
string AreaID = ddlCreateAddArea.SelectedItem.ToString();
con.Open();
OleDbCommand cmd = new OleDbCommand("select * from SlideShow where AreaName='" + AreaID + "' ", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
con.Close();
if (ddlCreateAddCategory.SelectedValue == "0")
{
}
}

public void ddlCreateAddCategory_SelectedIndexChanged(object sender, EventArgs e)
{
string CategoryID = ddlCreateAddCategory.SelectedItem.ToString();
string ArName = ddlCreateAddCategory.SelectedItem.ToString();
con.Open();
OleDbCommand cmd = new OleDbCommand("select * from SlideShowTable where CategoryName='" + CategoryID + "' And AreaName='" + ArName + "' ", con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
}
protected void btncreat_Click(object sender, EventArgs e)
{

////Get Filename from fileupload control
//String extention;
//String name = fileuploadimages.FileName;
//String name1 = name.ToUpper();

//if (name1.EndsWith(".JPG"))
// extention = ".JPG";
//else if (name1.EndsWith(".GIF"))
// extention = ".GIF";
//else if (name1.EndsWith(".JPEG"))
// extention = ".JPEG";
//else
// extention = "";


//String filename = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTi
Aarti Meswania at 12-Mar-13 5:27am
   
not sir I am girl
do you want to update row???
ashishadi at 12-Mar-13 5:30am
   
yes...mam..i want update the row..
Aarti Meswania at 12-Mar-13 5:32am
   
then write update query
like this

OleDbCommand cmd = new OleDbCommand("update SlideShowTable set ImageName = @ImageName, Description = @Description where CategoryID='" + txtcat.Text + "'And ArName='" + txtarea.Text + "' ", con);
ashishadi at 12-Mar-13 5:42am
   
mam...No value given for one or more required parameters....this error is occured.. :(
Aarti Meswania at 12-Mar-13 5:45am
   
don't say mam please

this error comes if you have not give parameters
e.g.
OleDbCommand cmd = new OleDbCommand("update SlideShowTable set ImageName = @ImageName, Description = @Description where CategoryID='" + txtcat.Text + "'And ArName='" + txtarea.Text + "' ", con);

in above query 2 parameters are there @ImageName, @Description make sure u have passed value for them


ashishadi at 12-Mar-13 5:48am
   
yaa..i have passed...den why dis happned...?...
Aarti Meswania at 12-Mar-13 5:59am
   
:(
try passing direct values not trough parameters
ashishadi at 12-Mar-13 6:03am
   
kk
ashishadi at 12-Mar-13 6:15am
   
Same Error.......
Aarti Meswania at 12-Mar-13 6:16am
   
debug & see what query u get & execute directly in sql
ashishadi at 12-Mar-13 6:30am
   
Aarti Meswania: can u join me with team viewer...
ashishadi at 12-Mar-13 7:08am
   
thanxsssssssssss a lot............
Aarti Meswania at 12-Mar-13 7:09am
   
welcome! :)
glad to help you! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 348
1 Sascha Lefévre 175
2 ProgramFOX 130
3 Maciej Los 110
4 Sergey Alexandrovich Kryukov 95
0 Sergey Alexandrovich Kryukov 8,980
1 OriginalGriff 7,263
2 Maciej Los 3,500
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | Last Updated 12 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100