2012-05-23 35 views
0

我有一個問題,我運行我的代碼,然後發生錯誤「發現SQL語句結束後的字符。SQL語句結束後發現的字符

,我的代碼是:

代碼

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 
    { 

    } 
} 

}

我不知道爲什麼?

Plz建議我。

「謝謝」

+0

您在插入語句中缺少引號。 –

回答

0

您必須將選擇標識作爲單獨的查詢運行。 Access一次只能運行一條語句。