Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. There is an error message when uploding files to Database.

There is an error message when uploding files to Database.

Scheduled Pinned Locked Moved ASP.NET
databasehelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lsh486love
    wrote on last edited by
    #1

    connString = "Provider=SQLOLEDB;Data Source = db.incheonlaw.ac.kr; Initial Catalog=stanlee;User ID=stanlee;Password=stan;"; using (OleDbConnection con = new OleDbConnection(ConnectionString)) using (OleDbCommand cmd = new OleDbCommand(CmdText, con)) { OleDbParameterCollection pms = cmd.Parameters; pms.Add("@Writing_Num", OleDbType.VarChar, 50); pms.Add("@FileName", OleDbType.VarChar, 200); pms.Add("@FileSize", OleDbType.Integer); pms.Add("@ContentType", OleDbType.VarChar, 50); pms.Add("@FileData", OleDbType.VarBinary); pms["@Writing_Num"].Value = writing_num; pms["@FileName"].Value = fileName; pms["@FileSize"].Value = fileLength; pms["@ContentType"].Value = contentType; pms["@FileData"].Value = fileData; pms = null; con.Open(); cmd.ExecuteNonQuery(); } All data of Writing_Num, FileName, FileSize, ContentType, FileData are normally operating. and when debuging "cmd.ExecuteNonQuery()", there is an error message, "Must declare the variable "@Writing_Num"; at this codes: catch (Exception ex) { buffer.Append("<li>Error Occurred: "); buffer.Append(ex.Message).Append("</li>"); }

    H G 2 Replies Last reply
    0
    • L lsh486love

      connString = "Provider=SQLOLEDB;Data Source = db.incheonlaw.ac.kr; Initial Catalog=stanlee;User ID=stanlee;Password=stan;"; using (OleDbConnection con = new OleDbConnection(ConnectionString)) using (OleDbCommand cmd = new OleDbCommand(CmdText, con)) { OleDbParameterCollection pms = cmd.Parameters; pms.Add("@Writing_Num", OleDbType.VarChar, 50); pms.Add("@FileName", OleDbType.VarChar, 200); pms.Add("@FileSize", OleDbType.Integer); pms.Add("@ContentType", OleDbType.VarChar, 50); pms.Add("@FileData", OleDbType.VarBinary); pms["@Writing_Num"].Value = writing_num; pms["@FileName"].Value = fileName; pms["@FileSize"].Value = fileLength; pms["@ContentType"].Value = contentType; pms["@FileData"].Value = fileData; pms = null; con.Open(); cmd.ExecuteNonQuery(); } All data of Writing_Num, FileName, FileSize, ContentType, FileData are normally operating. and when debuging "cmd.ExecuteNonQuery()", there is an error message, "Must declare the variable "@Writing_Num"; at this codes: catch (Exception ex) { buffer.Append("<li>Error Occurred: "); buffer.Append(ex.Message).Append("</li>"); }

      H Offline
      H Offline
      Herman T Instance
      wrote on last edited by
      #2

      adding cmd.Parameters.AddRange(pms.ToArray()); before con.Open would help

      In Word you can only store 2 bytes. That is why I use Writer.

      L 1 Reply Last reply
      0
      • H Herman T Instance

        adding cmd.Parameters.AddRange(pms.ToArray()); before con.Open would help

        In Word you can only store 2 bytes. That is why I use Writer.

        L Offline
        L Offline
        lsh486love
        wrote on last edited by
        #3

        There is no ToArray in components of pms. ERROR!! T^T....

        H 1 Reply Last reply
        0
        • L lsh486love

          There is no ToArray in components of pms. ERROR!! T^T....

          H Offline
          H Offline
          Herman T Instance
          wrote on last edited by
          #4

          then add each pms defined to cmd.parameters.Add() or did you try cmd.parameters.AddRange(pms) ?

          In Word you can only store 2 bytes. That is why I use Writer.

          1 Reply Last reply
          0
          • L lsh486love

            connString = "Provider=SQLOLEDB;Data Source = db.incheonlaw.ac.kr; Initial Catalog=stanlee;User ID=stanlee;Password=stan;"; using (OleDbConnection con = new OleDbConnection(ConnectionString)) using (OleDbCommand cmd = new OleDbCommand(CmdText, con)) { OleDbParameterCollection pms = cmd.Parameters; pms.Add("@Writing_Num", OleDbType.VarChar, 50); pms.Add("@FileName", OleDbType.VarChar, 200); pms.Add("@FileSize", OleDbType.Integer); pms.Add("@ContentType", OleDbType.VarChar, 50); pms.Add("@FileData", OleDbType.VarBinary); pms["@Writing_Num"].Value = writing_num; pms["@FileName"].Value = fileName; pms["@FileSize"].Value = fileLength; pms["@ContentType"].Value = contentType; pms["@FileData"].Value = fileData; pms = null; con.Open(); cmd.ExecuteNonQuery(); } All data of Writing_Num, FileName, FileSize, ContentType, FileData are normally operating. and when debuging "cmd.ExecuteNonQuery()", there is an error message, "Must declare the variable "@Writing_Num"; at this codes: catch (Exception ex) { buffer.Append("<li>Error Occurred: "); buffer.Append(ex.Message).Append("</li>"); }

            G Offline
            G Offline
            Greg Chelstowski
            wrote on last edited by
            #5

            How about not setting pms to null after you've put stuff in it?

            var question = (_2b || !(_2b));

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups