English 中文(简体)
Sql 语句结尾处缺失的分号
原标题:missing semicolon at end of sql statement

我有一个问题,当我朗姆我的代码, 然后错误发生时, “在 Sql 语句结尾漏掉分号 ” 。

我的代码是:

Code

    protected void btnSubmit_Click(object sender, EventArgs e)
    {

        try
        {
            FileUpload img = (FileUpload)imgUpload;
            Byte[] imgByte = null;
            if (img.HasFile && img.PostedFile != null)
            {
                //To create a PostedFile
                HttpPostedFile File = imgUpload.PostedFile;
                //Create byte Array with file len
                imgByte = new Byte[File.ContentLength];
                //force the control to load data in array
                File.InputStream.Read(imgByte, 0, File.ContentLength);
            }

            string str = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/Geeta/Desktop/mssl2.accdb;Persist Security Info=False";);


            OleDbConnection conn = new OleDbConnection(str);

            conn.Open();
            string sql = "INSERT INTO digital(Product_Name, Product_Code, Product_Price, Product_Image, Product_Description) VALUES(@pnm, @pcod, @ppr, @pimg, @pdes) SELECT @@IDENTITY;";
            OleDbCommand cmd = new OleDbCommand(sql, conn);

            cmd.Parameters.AddWithValue("@pnm", txtEName.Text.Trim());
            cmd.Parameters.AddWithValue("@pcod", txt_productcode.Text.Trim());
            cmd.Parameters.AddWithValue("@ppr", txt_productprice.Text.Trim());
            cmd.Parameters.AddWithValue("@pdes", txt_productdescri.Text.Trim());
            cmd.Parameters.AddWithValue("@pimg", imgByte);
            int Id = Convert.ToInt32(cmd.ExecuteScalar());
            lblResult.Text = String.Format("Employee ID is {0}", Id);
            conn.Close();

        }

        catch
        {
            lblResult.Text = "There was an error";
        }
        finally
        {

        }
    } 
}
问题回答

在选择“身份”之前添加分号。然后尝试执行。这意味着插入语句“一个分号”和“分号”。

Before "SELECT @@IDENTITY", you need a semi-colon. Technically you re creating two SQL statements. One for insert, and one for SELECT @@IDENTITY. That s why you need a semi-colon between those two queries.





相关问题
connect Access via c#

i need to open a connection to a remote access db. in the local environment to the remote acess db is working great . when i run this application from production server (other server) it s fail ...

total two or more values under one ID in SQL

![alt text][1] [1]: http://C:Documents and SettingsAdministratorMy DocumentsMy PicturesAshampoo Magical Snap 2Magical Snap - 2009.11.16 23.07 - 003.jpg In referring to the picture there are ...

How to show File Picker dialog in Access 2007?

I want to show a dialog where the user can pick a file, click OK, and then the path to the file will be saved in the database. I have just one problem, I can t figure out how tho show the dialog ...

MS Access: list macro from VBA

I have to deal with a few macros (not VBA) in an inherited Access application. In order to document them, I would like to print or list the actions in those macros, but I am very dissatisfied by ...

热门标签