0

i'm doing a simple foreach loop in an AsyncUpload collection to a Byte[] and trying to insert it into a database.

 foreach (UploadedFile file in AsyncUpload1.UploadedFiles)
        {

            string[] splitFileExt = file.FileName.Split('.');
            List<string> CommandArgs = new List<string>();
            CommandArgs.Add("IID|" + Request.QueryString["InstructorID"]);
            CommandArgs.Add("FName|" + file.FileName);
            CommandArgs.Add("FTitle|" + file.FileName);
            CommandArgs.Add("FType|" + file.ContentType);
            CommandArgs.Add("FExtension|" + splitFileExt[1]);
            CommandArgs.Add("FSize|" + file.ContentLength.ToString());
            byte[] b = StaticControlCreationClass.ReadToEnd(file.InputStream);
            MySQLProcessing.MySQLProcessor.MySQL_UploadFile(b, "fileupload", CommandArgs, mysqlCon);

        }



public static void MySQL_UploadFile(byte[] value, string MYSQLCommand, List<string> CommandArgs, MySqlConnection con)
    {
        MySqlCommand cmd = new MySqlCommand(MYSQLCommand, con);
        cmd.Parameters.AddWithValue("FContent", value);
        foreach (string args in CommandArgs)
        {
            string[] splitArgs = args.Split('|');
            cmd.Parameters.AddWithValue(splitArgs[0], splitArgs[1].Trim());
        }
        cmd.ExecuteNonQuery();

    }

and then here is the stored procedure

DROP PROCEDURE IF EXISTS fileupload;

CREATE PROCEDURE fileupload`(
   IID           int,
   TValue        varchar(250),
   FName         varchar(250),
   FType         varchar(15),
   FSize         varchar(45),
   FContent      longblob,
   FExtension    varchar(10))
   BEGIN
      SET @IID = IID;
      SET @TValue = TValue;
      SET @FName = FName;
      SET @FType = FType;
      SET @FSize = FSize;
      SET @FExtension = FExtension;
      SET @FContent = FContent;

      INSERT INTO tblfiles(rID,
                                     Title,
                                     File_Name,
                                     File_Type,
                                     File_Size,
                                     File_Content,
                                     File_Extension)
      VALUES (@IID,
              @TValue,
              @FName,
              @FType,
              @FSize,
              @FContent,
              @FExtension);
   END

i keep getting You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'fileupload' at line 1 @ cmd.ExecuteNonQuery();

Any help is appreciated.

1 Answer 1

1

I was missing the classifier to say it was a stored procedure

cmd.CommandType = CommandType.StoredProcedure;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.