本文介绍了在SQL语句结束时缺少分号(;)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 插入数据后... image 和 description not insert 该特定行 as am 使用 session ... 和错误是( SQL末尾缺少分号(;)声明。)和 我的下一个时间运行程序我可以在数据列表bt 中看到 image 数据库 .... plz告诉我......看下面的代码...... protected void btnSubmit_Click( object sender,EventArgs e) { // 从fileupload控件获取文件名 字符串 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 = ; 字符串 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); // 将图像保存到SlideImages文件夹 fileuploadimages.SaveAs (Server.MapPath( SlideImages / + filename)); // 打开数据库连接 con.Open(); // 查询将图像名称和描述插入数据库 OleDbCommand cmd = new OleDbCommand( 插入SlideShowTable(ImageName,Description)值(@ ImageName,@ Description)其中CategoryID =' + txtcat.Text + '和ArName =' + txtarea.Text + ',con); // 将参数传递给查询 cmd.Parameters.AddWithValue( @ ImageName,filename); cmd.Parameters.AddWithValue( @ Description,txtDesc.Text); cmd.ExecuteNonQuery(); // 关闭dbconnection txtDesc.Text = 串 .Empty; // BindDataList(); // string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName); string targetPath = Server.MapPath( SlideImages / + filename); Stream strm = fileuploadimages.PostedFile.InputStream; var targetFile = targetPath; // 基于scalefactor的图像大小会有所不同 GenerateThumbnails( 0 。 5 ,strm,targetFile); con.Close(); BindDataList(); } private void GenerateThumbnails( double scaleFactor,Stream sourcePath, string targetPath) { 使用( var image = Image.FromStream(sourcePath)) { var newWidth =( int )( 700 * scaleFactor); var newHeight =( int )( 700 * scaleFactor); var thumbnailImg = new 位图(newWidth,newHeight); var thumbGraph = Graphics.FromImage(thumbnailImg); thumbGraph.CompositingQuality = CompositingQuality.HighQuality; thumbGraph.SmoothingMode = SmoothingMode.HighQuality; thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic; var imageRectangle = new 矩形( 0 , 0 ,newWidth,newHeight); thumbGraph.DrawImage(image,imageRectangle); thumbnailImg.Save(targetPath,image.RawFormat); } } } 解决方案 查询错误.... 插入... 条件 错误 OleDbCommand cmd = new OleDbCommand( 插入SlideShowTable(ImageName,Description)值(@ ImageName,@ Description)其中CategoryID =' + txtcat.Text + '和ArName =' + txtarea.Text + ',con); 语法是 插入tblnm(列表。 ..)值(值列表......) 快乐编码! :) 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 btnot 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); } }} 解决方案 wrong query....Insert into ... with where condition is wrongOleDbCommand cmd = new OleDbCommand("Insert into SlideShowTable(ImageName,Description) values(@ImageName,@Description) where CategoryID='" + txtcat.Text + "'And ArName='" + txtarea.Text + "' ", con);syntax isInsert into tblnm(column list...) values(value list...)Happy Coding!:) 这篇关于在SQL语句结束时缺少分号(;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-03 21:33